Huge Script System Refactor
This commit is contained in:
parent
9e6ee7b2e2
commit
baba8f2e09
@ -1,32 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "DeerCore/Tools/Memory.h"
|
|
||||||
|
|
||||||
namespace Deer {
|
|
||||||
class ImGuiLayer;
|
|
||||||
namespace Core {
|
|
||||||
extern int argc;
|
|
||||||
extern char** argv;
|
|
||||||
} // namespace Core
|
|
||||||
|
|
||||||
class Timestep {
|
|
||||||
public:
|
|
||||||
Timestep(float time = 0.0f) : m_time(time) {}
|
|
||||||
|
|
||||||
float getSeconds() const { return m_time; }
|
|
||||||
float getMilliseconds() const { return m_time * 1000; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
float m_time;
|
|
||||||
};
|
|
||||||
|
|
||||||
namespace Application {
|
|
||||||
using Function = void (*)();
|
|
||||||
|
|
||||||
extern bool running;
|
|
||||||
|
|
||||||
void run();
|
|
||||||
void setTickCallback(Function);
|
|
||||||
|
|
||||||
void shutdown();
|
|
||||||
} // namespace Application
|
|
||||||
} // namespace Deer
|
|
||||||
12
Deer/Include/DeerCore/Engine.h
Normal file
12
Deer/Include/DeerCore/Engine.h
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
using Function = void (*)();
|
||||||
|
|
||||||
|
namespace Engine {
|
||||||
|
void init();
|
||||||
|
void shutdown();
|
||||||
|
|
||||||
|
void setUpdateCallback(Function);
|
||||||
|
} // namespace Engine
|
||||||
|
} // namespace Deer
|
||||||
@ -21,15 +21,6 @@ namespace Deer {
|
|||||||
class Entity;
|
class Entity;
|
||||||
|
|
||||||
class EntityEnvironment {
|
class EntityEnvironment {
|
||||||
// Note: Outdated note
|
|
||||||
///////// NOTES ///////////
|
|
||||||
// - The entity id means the position in a array defined in EntityEnvironment
|
|
||||||
// - The entity id is relative to a EntityEnvironment so it can be a complete
|
|
||||||
// diferent entity in other environments
|
|
||||||
// - The entity number 0 is allways the root
|
|
||||||
// - There is a limit defined by ENVIRONMENT_MAX_ENTITIES of how many
|
|
||||||
// entities can be in an EntityEnvironment
|
|
||||||
///////// NOTES ///////////
|
|
||||||
public:
|
public:
|
||||||
EntityEnvironment();
|
EntityEnvironment();
|
||||||
~EntityEnvironment();
|
~EntityEnvironment();
|
||||||
@ -40,17 +31,17 @@ namespace Deer {
|
|||||||
// Clears all entities
|
// Clears all entities
|
||||||
void clear();
|
void clear();
|
||||||
// Obtains the entity
|
// Obtains the entity
|
||||||
Entity& getEntity(uint16_t id);
|
Entity& getEntity(uint32_t id);
|
||||||
bool entityExists(uint16_t id) const;
|
bool entityExists(uint32_t id) const;
|
||||||
uint16_t getEntityCount() const;
|
uint32_t getEntityCount() const;
|
||||||
|
|
||||||
// Creates a entity child at root
|
// Creates a entity child at root
|
||||||
// WARNING: This method can change internal pointers and invalidate entitiy references
|
// WARNING: This method can change internal pointers and invalidate entitiy references
|
||||||
Entity& createEntity(const std::string& name = "");
|
Entity& createEntity(const std::string& name = "");
|
||||||
// Can be slow! This has to empty the stack of empty entities in case its necessary so use it in ascendent order!
|
// Can be slow! This has to empty the stack of empty entities in case its necessary so use it in ascendent order!
|
||||||
// WARNING: This method can change internal pointers and invalidate entitiy references
|
// WARNING: This method can change internal pointers and invalidate entitiy references
|
||||||
Entity& createEntityWithId(uint16_t id, const std::string& name = "");
|
Entity& createEntityWithId(uint32_t id, const std::string& name = "");
|
||||||
void destroyEntity(uint16_t id);
|
void destroyEntity(uint32_t id);
|
||||||
|
|
||||||
// Special behaviour
|
// Special behaviour
|
||||||
// WARNING: This method can change internal pointers and invalidate entitiy references
|
// WARNING: This method can change internal pointers and invalidate entitiy references
|
||||||
@ -76,22 +67,6 @@ namespace Deer {
|
|||||||
friend class Entity;
|
friend class Entity;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct EntityData {
|
|
||||||
int toDo;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct EntityEnvironmentData {
|
|
||||||
std::vector<EntityData> entities;
|
|
||||||
};
|
|
||||||
|
|
||||||
template <>
|
|
||||||
class ResourceBuilder<EntityEnvironment> {
|
|
||||||
public:
|
|
||||||
using BaseDataType = EntityEnvironmentData;
|
|
||||||
static Scope<EntityEnvironment> buildResource(const BaseDataType& baseData);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Warning: This calss does not initialize for performance
|
|
||||||
class Entity {
|
class Entity {
|
||||||
public:
|
public:
|
||||||
Entity() {}
|
Entity() {}
|
||||||
@ -103,9 +78,9 @@ namespace Deer {
|
|||||||
Entity& duplicate();
|
Entity& duplicate();
|
||||||
void destroy();
|
void destroy();
|
||||||
|
|
||||||
uint16_t getId() const { return entId; }
|
uint32_t getId() const { return entId; }
|
||||||
Entity& getParent() const;
|
Entity& getParent() const;
|
||||||
inline uint16_t getParentId() const { return parentId; }
|
inline uint32_t getParentId() const { return parentId; }
|
||||||
|
|
||||||
// TODO, enable transfer entitys from difrent environments
|
// TODO, enable transfer entitys from difrent environments
|
||||||
void setParent(Entity& parent);
|
void setParent(Entity& parent);
|
||||||
@ -125,10 +100,10 @@ namespace Deer {
|
|||||||
private:
|
private:
|
||||||
EntityEnvironment* environment = nullptr;
|
EntityEnvironment* environment = nullptr;
|
||||||
entt::entity entHandle = entt::null;
|
entt::entity entHandle = entt::null;
|
||||||
uint16_t entId = 0;
|
uint32_t entId = 0;
|
||||||
uint16_t parentId = 0;
|
uint32_t parentId = 0;
|
||||||
|
|
||||||
Entity(entt::entity handle, EntityEnvironment* scene, uint16_t entityID);
|
Entity(entt::entity handle, EntityEnvironment* scene, uint32_t entityID);
|
||||||
|
|
||||||
friend class EntityEnvironment;
|
friend class EntityEnvironment;
|
||||||
|
|
||||||
@ -139,8 +114,7 @@ namespace Deer {
|
|||||||
!environment->m_registry->all_of<T>(entHandle),
|
!environment->m_registry->all_of<T>(entHandle),
|
||||||
"Entity already have component {0}", typeid(T).name());
|
"Entity already have component {0}", typeid(T).name());
|
||||||
|
|
||||||
return environment->m_registry->emplace<T>(
|
return environment->m_registry->emplace<T>(entHandle, std::forward<Args>(args)...);
|
||||||
entHandle, std::forward<Args>(args)...);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
|||||||
41
Deer/Include/DeerCore/ScriptSystem.h
Normal file
41
Deer/Include/DeerCore/ScriptSystem.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "DeerCore/Tools/Memory.h"
|
||||||
|
#include "DeerCore/Tools/TypeDefs.h"
|
||||||
|
|
||||||
|
#include "angelscript.h"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class asIScriptEngine;
|
||||||
|
namespace Deer {
|
||||||
|
class ScriptEnvironment;
|
||||||
|
|
||||||
|
namespace ScriptSystem {
|
||||||
|
void init();
|
||||||
|
void shutdown();
|
||||||
|
|
||||||
|
asIScriptEngine* getScriptEngine();
|
||||||
|
Scope<ScriptEnvironment> createScriptEnvironment(const char* baseDataType);
|
||||||
|
} // namespace ScriptSystem
|
||||||
|
|
||||||
|
class EnvironmentSystems {
|
||||||
|
};
|
||||||
|
|
||||||
|
class ScriptInstance {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class EnvironmentInstances {
|
||||||
|
};
|
||||||
|
|
||||||
|
class ScriptEnvironment {
|
||||||
|
public:
|
||||||
|
private:
|
||||||
|
asIScriptContext* context;
|
||||||
|
std::string baseTypeName;
|
||||||
|
asITypeInfo* baseType;
|
||||||
|
|
||||||
|
ScriptEnvironment(asITypeInfo*);
|
||||||
|
friend Scope<ScriptEnvironment> Deer::ScriptSystem::createScriptEnvironment(const char* baseDataType);
|
||||||
|
};
|
||||||
|
} // namespace Deer
|
||||||
30
Deer/Include/DeerCore/Universe.h
Normal file
30
Deer/Include/DeerCore/Universe.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "DeerCore/Tools/Memory.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
class World;
|
||||||
|
class WorldSettings;
|
||||||
|
|
||||||
|
namespace Universe {
|
||||||
|
struct WorldHandle {
|
||||||
|
uint32_t worldId = 0;
|
||||||
|
uint32_t generation = 0;
|
||||||
|
|
||||||
|
WorldHandle() {}
|
||||||
|
WorldHandle(uint32_t _worldId, uint32_t _generation) : worldId(_worldId), generation(_generation) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
struct EntityHandle {
|
||||||
|
uint32_t entityId = 0;
|
||||||
|
WorldHandle worldId;
|
||||||
|
};
|
||||||
|
|
||||||
|
WorldHandle createWorld(const WorldSettings&);
|
||||||
|
World& getWorld(WorldHandle);
|
||||||
|
|
||||||
|
void destroyWorld(WorldHandle);
|
||||||
|
void destroyAllWorlds();
|
||||||
|
|
||||||
|
void flushDestroyedWorlds();
|
||||||
|
} // namespace Universe
|
||||||
|
} // namespace Deer
|
||||||
@ -1,30 +1,51 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "DeerCore/Tools/Memory.h"
|
||||||
#include "DeerCore/Tools/TypeDefs.h"
|
#include "DeerCore/Tools/TypeDefs.h"
|
||||||
|
|
||||||
|
#include <atomic>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
class EntityEnvironment;
|
class EntityEnvironment;
|
||||||
class WorldCamera;
|
|
||||||
class GizmoRenderer;
|
class GizmoRenderer;
|
||||||
|
class World;
|
||||||
|
|
||||||
namespace World {
|
struct WorldCamera;
|
||||||
// Clears all the assets and memory the World had conained
|
using WorldCallback = std::function<void(World&)>;
|
||||||
void clear();
|
|
||||||
|
|
||||||
// This is the cycle to execution of scripts and physics
|
|
||||||
void initExecution();
|
|
||||||
void tickExecution();
|
|
||||||
void endExecution();
|
|
||||||
|
|
||||||
bool getExecutingState();
|
|
||||||
uint32_t getCurrentExTick();
|
|
||||||
|
|
||||||
|
struct WorldSettings {
|
||||||
|
WorldCallback updateCallback;
|
||||||
|
u_int32_t updateFrequency;
|
||||||
#ifdef DEER_RENDER
|
#ifdef DEER_RENDER
|
||||||
// This function renders with the default camera in the environment
|
WorldCallback renderCallback;
|
||||||
void render();
|
u_int32_t renderFrequency;
|
||||||
void render(const WorldCamera&);
|
|
||||||
|
|
||||||
extern GizmoRenderer gizmoRenderer;
|
|
||||||
#endif
|
#endif
|
||||||
extern EntityEnvironment environment;
|
};
|
||||||
} // namespace World
|
|
||||||
|
enum class WorldState {
|
||||||
|
Created,
|
||||||
|
Executing,
|
||||||
|
StopRequested,
|
||||||
|
Stopped,
|
||||||
|
DestroyQueued,
|
||||||
|
ReadyToDestroy
|
||||||
|
};
|
||||||
|
|
||||||
|
class World {
|
||||||
|
public:
|
||||||
|
World(const WorldSettings&);
|
||||||
|
~World();
|
||||||
|
|
||||||
|
void execute();
|
||||||
|
void stopExecution();
|
||||||
|
void destroy();
|
||||||
|
|
||||||
|
WorldState getExecutionState();
|
||||||
|
Scope<EntityEnvironment> entityEnvironment;
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::atomic<WorldState> executingState;
|
||||||
|
WorldSettings worldSettings;
|
||||||
|
|
||||||
|
}; // namespace World
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
|
|||||||
@ -1,21 +0,0 @@
|
|||||||
#include "DeerCore/Application.h"
|
|
||||||
|
|
||||||
#ifdef DEER_RENDER
|
|
||||||
#include "DeerRender/Events/ApplicationEvent.h"
|
|
||||||
#include "DeerRender/Events/Event.h"
|
|
||||||
#include "DeerRender/Window.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace Deer {
|
|
||||||
namespace Application {
|
|
||||||
using EventFunction = void (*)(Event&);
|
|
||||||
|
|
||||||
void initWindow();
|
|
||||||
void shutdownWindow();
|
|
||||||
|
|
||||||
void setRenderCallback(Function);
|
|
||||||
void setEventCallback(EventFunction);
|
|
||||||
|
|
||||||
Window& getWindow();
|
|
||||||
} // namespace Application
|
|
||||||
} // namespace Deer
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "DeerCore/DataStore.h"
|
|
||||||
20
Deer/Include/DeerRender/Engine.h
Normal file
20
Deer/Include/DeerRender/Engine.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "DeerCore/Engine.h"
|
||||||
|
#include "DeerRender/Events/Event.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
using EventFunction = void (*)(Event&);
|
||||||
|
class World;
|
||||||
|
class Window;
|
||||||
|
|
||||||
|
namespace Engine {
|
||||||
|
void setRenderCallback(Function);
|
||||||
|
void setEventCallback(EventFunction);
|
||||||
|
|
||||||
|
void beginRender();
|
||||||
|
void endRender();
|
||||||
|
|
||||||
|
World& getMainWorld();
|
||||||
|
Window& getWindow();
|
||||||
|
} // namespace Engine
|
||||||
|
} // namespace Deer
|
||||||
@ -1,6 +1,4 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "DeerCore/Application.h"
|
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
class Input {
|
class Input {
|
||||||
public:
|
public:
|
||||||
|
|||||||
7
Deer/Include/DeerRender/ScriptSystem.h
Normal file
7
Deer/Include/DeerRender/ScriptSystem.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "DeerCore/ScriptSystem.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace ScriptSystem {
|
||||||
|
}
|
||||||
|
} // namespace Deer
|
||||||
2
Deer/Include/DeerRender/Universe.h
Normal file
2
Deer/Include/DeerRender/Universe.h
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "DeerCore/Universe.h"
|
||||||
@ -1,59 +0,0 @@
|
|||||||
#include "DeerCore/Application.h"
|
|
||||||
#include <functional>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
namespace Deer {
|
|
||||||
namespace Application {
|
|
||||||
// Implemented in DeerRender/Application
|
|
||||||
void runRender(float deltaTime);
|
|
||||||
void resolveEvents();
|
|
||||||
|
|
||||||
Function tickCallback;
|
|
||||||
bool running;
|
|
||||||
|
|
||||||
const double targetUpdateTime = 1.0 / 60.0; // Fixed 60 FPS update
|
|
||||||
double targetRenderTime = 1.0 / 160.0; // User-defined render FPS
|
|
||||||
|
|
||||||
void setTickCallback(Function _tick) {
|
|
||||||
tickCallback = _tick;
|
|
||||||
}
|
|
||||||
void run() {
|
|
||||||
running = true;
|
|
||||||
|
|
||||||
auto previousTime = std::chrono::high_resolution_clock::now();
|
|
||||||
double accumulatedUpdateTime = 0.0;
|
|
||||||
double accumulatedRenderTime = 0.0;
|
|
||||||
|
|
||||||
while (running) {
|
|
||||||
// Time handling
|
|
||||||
auto currentTime = std::chrono::high_resolution_clock::now();
|
|
||||||
std::chrono::duration<double> deltaTime = currentTime - previousTime;
|
|
||||||
previousTime = currentTime;
|
|
||||||
|
|
||||||
accumulatedUpdateTime += deltaTime.count();
|
|
||||||
accumulatedRenderTime += deltaTime.count();
|
|
||||||
|
|
||||||
// Fixed Update loop (60 FPS)
|
|
||||||
while (accumulatedUpdateTime >= targetUpdateTime) {
|
|
||||||
Timestep timestep = (float)targetUpdateTime;
|
|
||||||
accumulatedUpdateTime -= targetUpdateTime;
|
|
||||||
|
|
||||||
if (tickCallback)
|
|
||||||
tickCallback();
|
|
||||||
}
|
|
||||||
#ifdef DEER_RENDER
|
|
||||||
if (accumulatedRenderTime >= targetRenderTime) {
|
|
||||||
runRender((float)targetRenderTime);
|
|
||||||
accumulatedRenderTime -= targetRenderTime;
|
|
||||||
}
|
|
||||||
resolveEvents();
|
|
||||||
#endif
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void shutdown() {
|
|
||||||
running = false;
|
|
||||||
}
|
|
||||||
} // namespace Application
|
|
||||||
} // namespace Deer
|
|
||||||
52
Deer/src/DeerCore/Core/Engine.cpp
Normal file
52
Deer/src/DeerCore/Core/Engine.cpp
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
#ifndef DEER_RENDER
|
||||||
|
#include "DeerCore/Engine.h"
|
||||||
|
#include "DeerCore/Log.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace Engine {
|
||||||
|
Function renderCallback = nullptr;
|
||||||
|
Function updateCallback = nullptr;
|
||||||
|
} // namespace Engine
|
||||||
|
|
||||||
|
void Engine::setUpdateCallback(Function _update) {
|
||||||
|
updateCallback = _update;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::init() {
|
||||||
|
Log::init();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::shutdown() {
|
||||||
|
Log::shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::execute() {
|
||||||
|
bool running = true;
|
||||||
|
|
||||||
|
auto previousTime = std::chrono::high_resolution_clock::now();
|
||||||
|
double accumulatedUpdateTime = 0.0;
|
||||||
|
double accumulatedRenderTime = 0.0;
|
||||||
|
|
||||||
|
double targetUpdateTime = 1.0f / 50.0f;
|
||||||
|
double targetRenderTime = 1.0f / 144.0f;
|
||||||
|
|
||||||
|
while (running) {
|
||||||
|
auto currentTime = std::chrono::high_resolution_clock::now();
|
||||||
|
std::chrono::duration<double> deltaTime = currentTime - previousTime;
|
||||||
|
previousTime = currentTime;
|
||||||
|
|
||||||
|
accumulatedUpdateTime += deltaTime.count();
|
||||||
|
accumulatedRenderTime += deltaTime.count();
|
||||||
|
|
||||||
|
while (accumulatedUpdateTime >= targetUpdateTime) {
|
||||||
|
float timestep = targetUpdateTime;
|
||||||
|
accumulatedUpdateTime -= targetUpdateTime;
|
||||||
|
|
||||||
|
updateCallback();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} // namespace Deer
|
||||||
|
#endif
|
||||||
@ -1,210 +0,0 @@
|
|||||||
#include "DeerCore/DataStore.h"
|
|
||||||
#include "DeerCore/Log.h"
|
|
||||||
#include "DeerCore/Tools/Path.h"
|
|
||||||
|
|
||||||
#include "cereal/archives/portable_binary.hpp"
|
|
||||||
#include "cereal/cereal.hpp"
|
|
||||||
#include "cereal/types/unordered_map.hpp"
|
|
||||||
|
|
||||||
#include "DeerCore/DataStore/DataStructure.h"
|
|
||||||
#include "DeerCore/DataStore/DataStructureSerialization.h"
|
|
||||||
|
|
||||||
#include <fstream>
|
|
||||||
#include <ostream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <streambuf>
|
|
||||||
#include <unordered_map>
|
|
||||||
|
|
||||||
namespace Deer {
|
|
||||||
namespace DataStore {
|
|
||||||
Path rootPath = "./";
|
|
||||||
std::unordered_map<std::string, DirectoryData> dirData_cache;
|
|
||||||
} // namespace DataStore
|
|
||||||
|
|
||||||
const DirectoryData& DataStore::getDirData(const Path& id,
|
|
||||||
const Path& subDir,
|
|
||||||
const char* extension) {
|
|
||||||
std::string dirId = std::string(id) + "&" + std::string(subDir) + "&" +
|
|
||||||
std::string(extension);
|
|
||||||
if (dirData_cache.contains(dirId)) {
|
|
||||||
return dirData_cache[dirId];
|
|
||||||
}
|
|
||||||
|
|
||||||
Path idPath = rootPath / id;
|
|
||||||
|
|
||||||
Path searchPath = idPath / subDir;
|
|
||||||
|
|
||||||
DirectoryData& dirData = dirData_cache[dirId];
|
|
||||||
for (const auto& entry :
|
|
||||||
std::filesystem::directory_iterator(searchPath)) {
|
|
||||||
if (entry.is_directory())
|
|
||||||
dirData.dirs.push_back(entry.path().lexically_relative(idPath));
|
|
||||||
else if (entry.path().extension() == extension) {
|
|
||||||
Path ent = entry.path().lexically_relative(idPath);
|
|
||||||
dirData.elements.push_back(ent.parent_path() / ent.stem());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return dirData;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DataStore::loadFileData(const Path& id, const Path& name,
|
|
||||||
uint8_t** data, uint32_t* size) {
|
|
||||||
Path filePath = rootPath / id / name;
|
|
||||||
std::ifstream file(filePath, std::ios::in | std::ios::binary);
|
|
||||||
|
|
||||||
if (!file) {
|
|
||||||
file.close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.seekg(0, std::ios::end);
|
|
||||||
*size = (size_t)file.tellg();
|
|
||||||
file.seekg(0, std::ios::beg);
|
|
||||||
|
|
||||||
*data = new uint8_t[*size];
|
|
||||||
|
|
||||||
if (!file.read(reinterpret_cast<char*>(*data), *size)) {
|
|
||||||
DEER_CORE_ERROR("Failed to read file: {0}",
|
|
||||||
filePath.generic_string().c_str());
|
|
||||||
delete[] *data;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool DataStore::loadGlobalFileData(const Path& id, const Path& name,
|
|
||||||
uint8_t** data, uint32_t* size) {
|
|
||||||
Path filePath = rootPath / id;
|
|
||||||
for (auto& f :
|
|
||||||
std::filesystem::recursive_directory_iterator(filePath)) {
|
|
||||||
if (f.path().stem() == name) {
|
|
||||||
std::ifstream file(f.path(), std::ios::in | std::ios::binary);
|
|
||||||
|
|
||||||
if (!file) {
|
|
||||||
file.close();
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.seekg(0, std::ios::end);
|
|
||||||
*size = (size_t)file.tellg();
|
|
||||||
file.seekg(0, std::ios::beg);
|
|
||||||
|
|
||||||
*data = new uint8_t[*size];
|
|
||||||
|
|
||||||
if (!file.read(reinterpret_cast<char*>(*data), *size)) {
|
|
||||||
DEER_CORE_ERROR("Failed to read file: {0}",
|
|
||||||
filePath.generic_string().c_str());
|
|
||||||
delete[] *data;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
DEER_CORE_ERROR("File {0} not found", filePath.string().c_str());
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataStore::freeFileData(uint8_t* data) { delete[] data; }
|
|
||||||
|
|
||||||
void DataStore::deleteFile(const Path& path) {
|
|
||||||
Path filePath = rootPath / toLowerCasePath(path);
|
|
||||||
std::filesystem::remove(filePath);
|
|
||||||
}
|
|
||||||
|
|
||||||
uint8_t* DataStore::readFile(const Path& path, uint32_t* size) {
|
|
||||||
Path filePath = rootPath / path;
|
|
||||||
std::ifstream file(filePath, std::ios::in | std::ios::binary);
|
|
||||||
|
|
||||||
if (!file) {
|
|
||||||
file.close();
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.seekg(0, std::ios::end);
|
|
||||||
*size = (size_t)file.tellg();
|
|
||||||
file.seekg(0, std::ios::beg);
|
|
||||||
|
|
||||||
uint8_t* buffer = new uint8_t[*size];
|
|
||||||
|
|
||||||
if (!file.read(reinterpret_cast<char*>(buffer), *size)) {
|
|
||||||
DEER_CORE_ERROR("Failed to read file: {0}",
|
|
||||||
filePath.generic_string().c_str());
|
|
||||||
delete[] buffer;
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
file.close();
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataStore::saveFile(const Path& path, uint8_t* data, uint32_t size) {
|
|
||||||
Path filePath = rootPath / toLowerCasePath(path);
|
|
||||||
std::filesystem::create_directories(filePath.parent_path());
|
|
||||||
|
|
||||||
std::ofstream file(filePath, std::ios::out | std::ios::binary);
|
|
||||||
|
|
||||||
DEER_CORE_ASSERT(file, "Error when writing file {0}",
|
|
||||||
filePath.generic_string().c_str());
|
|
||||||
|
|
||||||
file.write(reinterpret_cast<const char*>(data), size);
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataStore::compressFiles(std::vector<Path> files, const Path& path) {
|
|
||||||
std::unordered_map<Path, DataStructure> dataStructure;
|
|
||||||
std::vector<uint8_t> combinedData;
|
|
||||||
|
|
||||||
for (const Path& inputPath : files) {
|
|
||||||
uint32_t fileSize = 0;
|
|
||||||
uint8_t* fileData = readFile(inputPath, &fileSize);
|
|
||||||
|
|
||||||
uint32_t start = combinedData.size();
|
|
||||||
|
|
||||||
combinedData.insert(combinedData.end(), fileData,
|
|
||||||
fileData + fileSize);
|
|
||||||
dataStructure[inputPath] = DataStructure{.dataPath = inputPath,
|
|
||||||
.dataStart = start,
|
|
||||||
.dataSize = fileSize};
|
|
||||||
|
|
||||||
delete[] fileData;
|
|
||||||
}
|
|
||||||
|
|
||||||
Path compressedPath = path;
|
|
||||||
compressedPath += ".deer";
|
|
||||||
Path metaPath = path;
|
|
||||||
metaPath += ".deer.meta";
|
|
||||||
|
|
||||||
std::stringstream buffer;
|
|
||||||
{
|
|
||||||
cereal::PortableBinaryOutputArchive archive(buffer);
|
|
||||||
archive(dataStructure);
|
|
||||||
}
|
|
||||||
|
|
||||||
saveFile(compressedPath, combinedData.data(), combinedData.size());
|
|
||||||
saveFile(metaPath, (uint8_t*)buffer.str().c_str(), buffer.str().size());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Path> DataStore::getFiles(const Path& path, const std::string& extension) {
|
|
||||||
std::vector<Path> files;
|
|
||||||
Path lookPath = rootPath / path;
|
|
||||||
|
|
||||||
for (const auto& entry :
|
|
||||||
std::filesystem::recursive_directory_iterator(lookPath)) {
|
|
||||||
if (std::filesystem::is_regular_file(entry) &&
|
|
||||||
entry.path().extension() == extension) {
|
|
||||||
files.push_back(entry.path().lexically_relative(rootPath));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return files;
|
|
||||||
}
|
|
||||||
|
|
||||||
void DataStore::createFolder(const Path& path) {
|
|
||||||
std::filesystem::create_directories(path);
|
|
||||||
}
|
|
||||||
} // namespace Deer
|
|
||||||
39
Deer/src/DeerCore/ScriptSystem/EngineRegistry.cpp
Normal file
39
Deer/src/DeerCore/ScriptSystem/EngineRegistry.cpp
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
#include "DeerCore/ScriptSystem.h"
|
||||||
|
#include "DeerCore/ScriptSystem/Helpers.h"
|
||||||
|
#include "DeerCore/ScriptSystem/InternalAPI/Engine.h"
|
||||||
|
#include "angelscript.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace ScriptSystem {
|
||||||
|
extern asIScriptEngine* scriptEngine;
|
||||||
|
|
||||||
|
void registerEngine();
|
||||||
|
|
||||||
|
void registerEngineFunctions();
|
||||||
|
void registerEngineStructs();
|
||||||
|
} // namespace ScriptSystem
|
||||||
|
|
||||||
|
void ScriptSystem::registerEngineFunctions() {
|
||||||
|
REGISTER_GLOBAL_FUNC(scriptEngine, "string getParent(const string&in path)", getParentPath);
|
||||||
|
REGISTER_GLOBAL_FUNC(scriptEngine, "string getParentName(const string&in path)", getParentPathName);
|
||||||
|
REGISTER_GLOBAL_FUNC(scriptEngine, "string getName(const string&in path)", getPathName);
|
||||||
|
REGISTER_GLOBAL_FUNC(scriptEngine, "array<string>@ divide(const string&in path)", dividePath_angelscript);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptSystem::registerEngineStructs() {
|
||||||
|
AS_RET_CHECK(scriptEngine->RegisterInterface("Panel"));
|
||||||
|
AS_RET_CHECK(scriptEngine->RegisterInterfaceMethod("Panel", "void render()"));
|
||||||
|
AS_RET_CHECK(scriptEngine->RegisterInterface("Service"));
|
||||||
|
|
||||||
|
AS_CHECK(scriptEngine->RegisterFuncdef("void SimpleFunction()"));
|
||||||
|
AS_CHECK(scriptEngine->RegisterFuncdef("void ReciverFunction(any@)"));
|
||||||
|
AS_CHECK(scriptEngine->RegisterFuncdef("void TransferFunction(any@, any@)"));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptSystem::registerEngine() {
|
||||||
|
registerEngineStructs();
|
||||||
|
scriptEngine->SetDefaultNamespace("Path");
|
||||||
|
registerEngineFunctions();
|
||||||
|
scriptEngine->SetDefaultNamespace("");
|
||||||
|
}
|
||||||
|
} // namespace Deer
|
||||||
64
Deer/src/DeerCore/ScriptSystem/Helpers.cpp
Normal file
64
Deer/src/DeerCore/ScriptSystem/Helpers.cpp
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#include "DeerCore/ScriptSystem/Helpers.h"
|
||||||
|
#include "angelscript.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace ScriptSystem {
|
||||||
|
const char* getAngelScriptReturnCodeString(int code) {
|
||||||
|
switch (code) {
|
||||||
|
case asSUCCESS:
|
||||||
|
return "SUCCESS (The operation was successful)";
|
||||||
|
case asERROR:
|
||||||
|
return "ERROR (A generic error occurred)";
|
||||||
|
case asCONTEXT_ACTIVE:
|
||||||
|
return "CONTEXT_ACTIVE (A context was active during an invalid operation)";
|
||||||
|
case asCONTEXT_NOT_FINISHED:
|
||||||
|
return "CONTEXT_NOT_FINISHED (Context has not finished execution)";
|
||||||
|
case asCONTEXT_NOT_PREPARED:
|
||||||
|
return "CONTEXT_NOT_PREPARED (Context is not prepared)";
|
||||||
|
case asINVALID_ARG:
|
||||||
|
return "INVALID_ARG (An invalid argument was provided)";
|
||||||
|
case asNO_FUNCTION:
|
||||||
|
return "NO_FUNCTION (Function not found)";
|
||||||
|
case asNOT_SUPPORTED:
|
||||||
|
return "NOT_SUPPORTED (Feature not supported by build configuration)";
|
||||||
|
case asINVALID_NAME:
|
||||||
|
return "INVALID_NAME (Name is not allowed or invalid)";
|
||||||
|
case asNAME_TAKEN:
|
||||||
|
return "NAME_TAKEN (Name is already taken by another entity)";
|
||||||
|
case asINVALID_DECLARATION:
|
||||||
|
return "INVALID_DECLARATION (The declaration is invalid)";
|
||||||
|
case asINVALID_OBJECT:
|
||||||
|
return "INVALID_OBJECT (Invalid object handle or object type)";
|
||||||
|
case asINVALID_TYPE:
|
||||||
|
return "INVALID_TYPE (Invalid type provided)";
|
||||||
|
case asALREADY_REGISTERED:
|
||||||
|
return "ALREADY_REGISTERED (Item is already registered)";
|
||||||
|
case asMULTIPLE_FUNCTIONS:
|
||||||
|
return "MULTIPLE_FUNCTIONS (More than one matching function found)";
|
||||||
|
case asNO_MODULE:
|
||||||
|
return "NO_MODULE (Module was not found)";
|
||||||
|
case asNO_GLOBAL_VAR:
|
||||||
|
return "NO_GLOBAL_VAR (Global variable was not found)";
|
||||||
|
case asINVALID_CONFIGURATION:
|
||||||
|
return "INVALID_CONFIGURATION (Invalid configuration, likely during registration)";
|
||||||
|
case asINVALID_INTERFACE:
|
||||||
|
return "INVALID_INTERFACE (Invalid interface registration)";
|
||||||
|
case asCANT_BIND_ALL_FUNCTIONS:
|
||||||
|
return "CANT_BIND_ALL_FUNCTIONS (Couldn't bind all functions for a virtual interface)";
|
||||||
|
case asLOWER_ARRAY_DIMENSION_NOT_REGISTERED:
|
||||||
|
return "LOWER_ARRAY_DIMENSION_NOT_REGISTERED (Lower dimension type for array not registered)";
|
||||||
|
default:
|
||||||
|
return "Unknown AngelScript error code";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ImplementsInterface(asITypeInfo* type, asITypeInfo* iface) {
|
||||||
|
for (uint32_t i = 0; i < type->GetInterfaceCount(); i++) {
|
||||||
|
if (type->GetInterface(i) == iface)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ScriptSystem
|
||||||
|
} // namespace Deer
|
||||||
57
Deer/src/DeerCore/ScriptSystem/Helpers.h
Normal file
57
Deer/src/DeerCore/ScriptSystem/Helpers.h
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "DeerRender/Log.h"
|
||||||
|
#include "angelscript.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace ScriptSystem {
|
||||||
|
const char* getAngelScriptReturnCodeString(int code);
|
||||||
|
bool ImplementsInterface(asITypeInfo* type, asITypeInfo* iface);
|
||||||
|
} // namespace ScriptSystem
|
||||||
|
} // namespace Deer
|
||||||
|
|
||||||
|
#define REGISTER_GLOBAL_FUNC(scriptEngine, funcdef, func) \
|
||||||
|
AS_CHECK(scriptEngine->RegisterGlobalFunction( \
|
||||||
|
funcdef, \
|
||||||
|
asFUNCTION(func), asCALL_CDECL))
|
||||||
|
|
||||||
|
#define REGISTER_OBJECT_METHOD(scriptEngine, clasdef, funcdef, clas, func) \
|
||||||
|
AS_CHECK(scriptEngine->RegisterObjectMethod( \
|
||||||
|
clasdef, funcdef, \
|
||||||
|
asMETHOD(clas, func), asCALL_THISCALL))
|
||||||
|
|
||||||
|
#define REGISTER_EXT_OBJECT_METHOD(scriptEngine, clasdef, funcdef, func) \
|
||||||
|
AS_CHECK(scriptEngine->RegisterObjectMethod( \
|
||||||
|
clasdef, funcdef, \
|
||||||
|
asFUNCTION(func), asCALL_CDECL_OBJLAST))
|
||||||
|
|
||||||
|
#define REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, clasdef, funcdef, func) \
|
||||||
|
AS_CHECK(scriptEngine->RegisterObjectBehaviour( \
|
||||||
|
clasdef, asBEHAVE_CONSTRUCT, funcdef, \
|
||||||
|
asFUNCTION(func), asCALL_CDECL_OBJLAST))
|
||||||
|
#define REGISTER_EXT_OBJECT_DESTRUCTOR(scriptEngine, clasdef, funcdef, func) \
|
||||||
|
AS_CHECK(scriptEngine->RegisterObjectBehaviour( \
|
||||||
|
clasdef, asBEHAVE_DESTRUCT, funcdef, \
|
||||||
|
asFUNCTION(func), asCALL_CDECL_OBJLAST))
|
||||||
|
|
||||||
|
#define AS_CHECK(f) \
|
||||||
|
{ \
|
||||||
|
int __r = f; \
|
||||||
|
if (__r < 0) { \
|
||||||
|
DEER_EDITOR_ENGINE_ERROR("Error at line: {0}:{1} -> {2}", __FILE__, __LINE__, Deer::ScriptSystem::getAngelScriptReturnCodeString(__r)); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
#define AS_CHECK_ADDITIONAL_INFO(f, i) \
|
||||||
|
{ \
|
||||||
|
int __r = f; \
|
||||||
|
if (__r < 0) { \
|
||||||
|
DEER_EDITOR_ENGINE_ERROR("Error at line: {0}:{1} -> {2} \n {3}", __FILE__, __LINE__, Deer::ScriptSystem::getAngelScriptReturnCodeString(__r), i); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
|
#define AS_RET_CHECK(f) \
|
||||||
|
{ \
|
||||||
|
int __r = f; \
|
||||||
|
if (__r < 0) { \
|
||||||
|
DEER_EDITOR_ENGINE_ERROR("Error at line: {0}:{1} -> {2}", __FILE__, __LINE__, Deer::ScriptSystem::getAngelScriptReturnCodeString(__r)); \
|
||||||
|
return; \
|
||||||
|
} \
|
||||||
|
}
|
||||||
41
Deer/src/DeerCore/ScriptSystem/InternalAPI/Engine.cpp
Normal file
41
Deer/src/DeerCore/ScriptSystem/InternalAPI/Engine.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#include "DeerCore/ScriptSystem/InternalAPI/Engine.h"
|
||||||
|
#include "DeerRender/Tools/Path.h"
|
||||||
|
|
||||||
|
#include "angelscript.h"
|
||||||
|
#include "scriptarray.h"
|
||||||
|
#include "scriptstdstring.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace ScriptSystem {
|
||||||
|
extern asIScriptEngine* scriptEngine;
|
||||||
|
|
||||||
|
std::string getParentPath(std::string& path) {
|
||||||
|
return Path(path).parent_path().string();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getParentPathName(std::string& path) {
|
||||||
|
return Path(path).parent_path().stem().string();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string getPathName(std::string& path) {
|
||||||
|
return Path(path).stem().string();
|
||||||
|
}
|
||||||
|
|
||||||
|
CScriptArray* dividePath_angelscript(std::string& path_s) {
|
||||||
|
asITypeInfo* arrayStringType = scriptEngine->GetTypeInfoByDecl("array<string>");
|
||||||
|
CScriptArray* array = CScriptArray::Create(arrayStringType);
|
||||||
|
|
||||||
|
Path path_p(path_s);
|
||||||
|
for (const auto& part : path_p) {
|
||||||
|
std::string s = part.string();
|
||||||
|
|
||||||
|
array->Resize(array->GetSize() + 1);
|
||||||
|
array->SetValue(array->GetSize() - 1, &s);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
} // namespace ScriptSystem
|
||||||
|
} // namespace Deer
|
||||||
@ -4,11 +4,10 @@
|
|||||||
class CScriptArray;
|
class CScriptArray;
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace StudioAPI {
|
namespace ScriptSystem {
|
||||||
// ANGELSCRIPT SPECIFIC
|
|
||||||
CScriptArray* dividePath_angelscript(std::string&);
|
CScriptArray* dividePath_angelscript(std::string&);
|
||||||
std::string getParentPath(std::string&);
|
std::string getParentPath(std::string&);
|
||||||
std::string getParentPathName(std::string&);
|
std::string getParentPathName(std::string&);
|
||||||
std::string getPathName(std::string&);
|
std::string getPathName(std::string&);
|
||||||
} // namespace StudioAPI
|
} // namespace ScriptSystem
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
91
Deer/src/DeerCore/ScriptSystem/InternalAPI/Entity.h
Normal file
91
Deer/src/DeerCore/ScriptSystem/InternalAPI/Entity.h
Normal file
@ -0,0 +1,91 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "DeerCore/Universe.h"
|
||||||
|
|
||||||
|
#include "DeerRender/Mesh.h"
|
||||||
|
#include "DeerRender/Shader.h"
|
||||||
|
#include "DeerRender/Texture.h"
|
||||||
|
|
||||||
|
#include "glm/glm.hpp"
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class asIScriptGeneric;
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace StudioAPI {
|
||||||
|
Universe::EntityHandle entity_getSelf(Universe::EntityHandle);
|
||||||
|
std::string entity_getName(Universe::EntityHandle);
|
||||||
|
void entity_getName(std::string, Universe::EntityHandle);
|
||||||
|
bool entity_exists(Universe::EntityHandle);
|
||||||
|
bool entity_isRoot(Universe::EntityHandle);
|
||||||
|
void entity_destroy(Universe::EntityHandle);
|
||||||
|
|
||||||
|
Universe::EntityHandle entity_createChild(Universe::EntityHandle);
|
||||||
|
void entity_setParent(Universe::EntityHandle);
|
||||||
|
Universe::EntityHandle entity_getParent(Universe::EntityHandle);
|
||||||
|
|
||||||
|
bool entity_isDescendantOf(Universe::EntityHandle);
|
||||||
|
bool entity_opEquals(Universe::EntityHandle& other, Universe::EntityHandle);
|
||||||
|
bool entity_isDescendantOf(Universe::EntityHandle parent);
|
||||||
|
bool entity_opEquals(const Universe::EntityHandle& other);
|
||||||
|
|
||||||
|
void entity_addGenericComponent(asIScriptGeneric* generic);
|
||||||
|
void entity_removeGenericComponent(asIScriptGeneric* generic);
|
||||||
|
void entity_getGenericComponent(asIScriptGeneric* generic);
|
||||||
|
void entity_hasGenericComponent(asIScriptGeneric* generic);
|
||||||
|
|
||||||
|
struct TransformComponentStruct : Universe::EntityHandle {
|
||||||
|
glm::vec3 getPosition();
|
||||||
|
glm::vec3 getScale();
|
||||||
|
glm::vec3 getRotation();
|
||||||
|
|
||||||
|
void setPosition(glm::vec3);
|
||||||
|
void setScale(glm::vec3);
|
||||||
|
void setRotation(glm::vec3);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct MeshComponentStruct : Universe::EntityHandle {
|
||||||
|
bool isActive();
|
||||||
|
void setActive(bool);
|
||||||
|
|
||||||
|
bool hasMesh();
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
Resource<GPUMesh> getMesh();
|
||||||
|
void setMesh(Resource<GPUMesh>);
|
||||||
|
|
||||||
|
bool assertMeshComponent(const char* funcName);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct ShaderComponentStruct : Universe::EntityHandle {
|
||||||
|
bool hasShader();
|
||||||
|
void clear();
|
||||||
|
|
||||||
|
Resource<Shader> getShader();
|
||||||
|
void setShader(Resource<Shader>);
|
||||||
|
|
||||||
|
Resource<Texture> getTexture();
|
||||||
|
void setTexture(Resource<Texture>);
|
||||||
|
|
||||||
|
bool assertShaderComponent(const char* funcName);
|
||||||
|
};
|
||||||
|
|
||||||
|
struct CameraComponentStruct : Universe::EntityHandle {
|
||||||
|
float getFov();
|
||||||
|
float getAspectRation();
|
||||||
|
float getNearZ();
|
||||||
|
float getFarZ();
|
||||||
|
|
||||||
|
void setFov(float);
|
||||||
|
void setAspectRation(float);
|
||||||
|
void setNearZ(float);
|
||||||
|
void setFarZ(float);
|
||||||
|
|
||||||
|
bool assertCameraComponent(const char* funcName);
|
||||||
|
};
|
||||||
|
|
||||||
|
Universe::EntityHandle getRoot();
|
||||||
|
void constructEntityStruct(int id, void* memory);
|
||||||
|
void copyEntityStruct(int id, void* memory);
|
||||||
|
} // namespace StudioAPI
|
||||||
|
} // namespace Deer
|
||||||
@ -0,0 +1,21 @@
|
|||||||
|
#include "DeerCore/ScriptSystem/InternalAPI/InternalFunctions.h"
|
||||||
|
#include "DeerRender/Log.h"
|
||||||
|
#include "angelscript.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
void ScriptSystem::errorCallback_angelscript(const asSMessageInfo* msg, void* param) {
|
||||||
|
if (msg->type == asMSGTYPE_WARNING) {
|
||||||
|
DEER_EDITOR_ENGINE_WARN("{0}:{1}:{2}) : {3}", msg->section, msg->row, msg->col, msg->message);
|
||||||
|
} else if (msg->type == asMSGTYPE_INFORMATION) {
|
||||||
|
DEER_EDITOR_ENGINE_INFO("{0}:{1}:{2}) : {3}", msg->section, msg->row, msg->col, msg->message);
|
||||||
|
} else if (msg->type == asMSGTYPE_ERROR) {
|
||||||
|
DEER_EDITOR_ENGINE_ERROR("{0}:{1}:{2}) : {3}", msg->section, msg->row, msg->col, msg->message);
|
||||||
|
} else {
|
||||||
|
DEER_EDITOR_ENGINE_INFO("{0}:{1}:{2}) : {3}", msg->section, msg->row, msg->col, msg->message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptSystem::print(std::string& msg) {
|
||||||
|
DEER_EDITOR_ENGINE_INFO("{0}", msg.c_str());
|
||||||
|
}
|
||||||
|
} // namespace Deer
|
||||||
@ -1,11 +1,9 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include "string"
|
struct asSMessageInfo;
|
||||||
|
|
||||||
class asSMessageInfo;
|
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace StudioAPI {
|
namespace ScriptSystem {
|
||||||
void errorCallback_angelscript(const asSMessageInfo* msg, void* param);
|
void errorCallback_angelscript(const asSMessageInfo* msg, void* param);
|
||||||
void print(std::string& msg);
|
void print(std::string& msg);
|
||||||
} // namespace StudioAPI
|
} // namespace ScriptSystem
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
66
Deer/src/DeerCore/ScriptSystem/InternalAPI/Math.cpp
Normal file
66
Deer/src/DeerCore/ScriptSystem/InternalAPI/Math.cpp
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
#include "DeerCore/ScriptSystem/InternalAPI/Math.h"
|
||||||
|
#include "glm/glm.hpp"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace ScriptSystem {
|
||||||
|
void vec3_constructor_params(float x, float y, float z, void* mem) {
|
||||||
|
new (mem) glm::vec3(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 vec3_add(glm::vec3& value, glm::vec3& self) {
|
||||||
|
return self + value;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 vec3_sub(const glm::vec3& value, glm::vec3& self) {
|
||||||
|
return self - value;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 vec3_neg(glm::vec3& self) {
|
||||||
|
return -self;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 vec3_mult(float value, glm::vec3& self) {
|
||||||
|
return self * value;
|
||||||
|
}
|
||||||
|
|
||||||
|
void quat_construct(glm::quat* mem) {
|
||||||
|
new (mem) glm::quat();
|
||||||
|
}
|
||||||
|
|
||||||
|
void quat_copyConstruct(glm::quat* data, glm::quat* mem) {
|
||||||
|
new (mem) glm::quat(*data);
|
||||||
|
}
|
||||||
|
|
||||||
|
void quat_constructFromValue(float x, float y, float z, float w, glm::quat* mem) {
|
||||||
|
new (mem) glm::quat(x, y, z, w);
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 quat_getEuler(glm::quat* mem) {
|
||||||
|
return glm::degrees(glm::eulerAngles(*mem));
|
||||||
|
}
|
||||||
|
|
||||||
|
void quat_setEuler(glm::vec3 euler, glm::quat* mem) {
|
||||||
|
new (mem) glm::quat(glm::radians(euler));
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::quat quat_multiply(glm::quat* data, glm::quat* mem) {
|
||||||
|
return *mem * *data;
|
||||||
|
}
|
||||||
|
|
||||||
|
glm::vec3 transform_relative(glm::vec3 pos, TransformComponent* transform) {
|
||||||
|
return transform->getMatrix() * glm::vec4(pos, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
void transform_construct(TransformComponent* mem) {
|
||||||
|
new (mem) TransformComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
void camera_construct(CameraComponent* mem) {
|
||||||
|
new (mem) CameraComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
void sceneCamera_Construct(WorldCamera* mem) {
|
||||||
|
new (mem) WorldCamera();
|
||||||
|
}
|
||||||
|
} // namespace ScriptSystem
|
||||||
|
} // namespace Deer
|
||||||
@ -6,7 +6,7 @@
|
|||||||
#include "DeerRender/World.h"
|
#include "DeerRender/World.h"
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace StudioAPI {
|
namespace ScriptSystem {
|
||||||
void vec3_constructor(void*);
|
void vec3_constructor(void*);
|
||||||
void vec3_constructor_params(float, float, float, void*);
|
void vec3_constructor_params(float, float, float, void*);
|
||||||
|
|
||||||
@ -17,7 +17,6 @@ namespace Deer {
|
|||||||
|
|
||||||
void quat_construct(glm::quat*);
|
void quat_construct(glm::quat*);
|
||||||
void quat_copyConstruct(glm::quat*, glm::quat*);
|
void quat_copyConstruct(glm::quat*, glm::quat*);
|
||||||
void quat_destruct(glm::quat*);
|
|
||||||
void quat_constructFromValue(float, float, float, float, glm::quat*);
|
void quat_constructFromValue(float, float, float, float, glm::quat*);
|
||||||
|
|
||||||
glm::vec3 quat_getEuler(glm::quat*);
|
glm::vec3 quat_getEuler(glm::quat*);
|
||||||
@ -31,5 +30,5 @@ namespace Deer {
|
|||||||
glm::vec3 transform_relative(glm::vec3, TransformComponent*);
|
glm::vec3 transform_relative(glm::vec3, TransformComponent*);
|
||||||
|
|
||||||
void emptyDestructor();
|
void emptyDestructor();
|
||||||
} // namespace StudioAPI
|
} // namespace ScriptSystem
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
8
Deer/src/DeerCore/ScriptSystem/InternalAPI/World.h
Normal file
8
Deer/src/DeerCore/ScriptSystem/InternalAPI/World.h
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "DeerCore/Universe.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace ScriptSystem {
|
||||||
|
Universe::WorldHandle getExecutingWorld();
|
||||||
|
}
|
||||||
|
} // namespace Deer
|
||||||
68
Deer/src/DeerCore/ScriptSystem/MathRegistry.cpp
Normal file
68
Deer/src/DeerCore/ScriptSystem/MathRegistry.cpp
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
#include "DeerCore/ScriptSystem.h"
|
||||||
|
#include "DeerCore/ScriptSystem/Helpers.h"
|
||||||
|
#include "DeerCore/ScriptSystem/InternalAPI/Math.h"
|
||||||
|
#include "angelscript.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace ScriptSystem {
|
||||||
|
extern asIScriptEngine* scriptEngine;
|
||||||
|
|
||||||
|
void registerMath();
|
||||||
|
void registerMathStructs();
|
||||||
|
void registerMathFunctions();
|
||||||
|
} // namespace ScriptSystem
|
||||||
|
|
||||||
|
void ScriptSystem::registerMathStructs() {
|
||||||
|
scriptEngine->RegisterObjectType("quat", sizeof(glm::vec3), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<glm::quat>() | asOBJ_APP_CLASS_ALLFLOATS);
|
||||||
|
scriptEngine->RegisterObjectProperty("vec3", "float x", asOFFSET(glm::vec3, x));
|
||||||
|
scriptEngine->RegisterObjectProperty("vec3", "float y", asOFFSET(glm::vec3, y));
|
||||||
|
scriptEngine->RegisterObjectProperty("vec3", "float z", asOFFSET(glm::vec3, z));
|
||||||
|
REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "vec3", "void f()", vec3_constructor);
|
||||||
|
REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "vec3", "void f(float, float = 0, float = 0)", vec3_constructor_params);
|
||||||
|
|
||||||
|
scriptEngine->RegisterObjectType("quat", sizeof(glm::quat), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<glm::quat>() | asOBJ_APP_CLASS_ALLFLOATS);
|
||||||
|
scriptEngine->RegisterObjectProperty("quat", "float x", asOFFSET(glm::quat, x));
|
||||||
|
scriptEngine->RegisterObjectProperty("quat", "float y", asOFFSET(glm::quat, y));
|
||||||
|
scriptEngine->RegisterObjectProperty("quat", "float z", asOFFSET(glm::quat, z));
|
||||||
|
scriptEngine->RegisterObjectProperty("quat", "float w", asOFFSET(glm::quat, w));
|
||||||
|
REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "quat", "void f()", quat_construct);
|
||||||
|
REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "quat", "void f(float, float, float, float)", quat_constructFromValue);
|
||||||
|
|
||||||
|
scriptEngine->RegisterObjectType("Transform", sizeof(TransformComponent), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<TransformComponent>());
|
||||||
|
scriptEngine->RegisterObjectProperty("Transform", "vec3 position", asOFFSET(TransformComponent, position));
|
||||||
|
scriptEngine->RegisterObjectProperty("Transform", "vec3 scale", asOFFSET(TransformComponent, scale));
|
||||||
|
scriptEngine->RegisterObjectProperty("Transform", "quat rotation", asOFFSET(TransformComponent, rotation));
|
||||||
|
REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "Transform", "void f()", transform_construct);
|
||||||
|
|
||||||
|
scriptEngine->RegisterObjectType("Camera", sizeof(CameraComponent), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<CameraComponent>());
|
||||||
|
scriptEngine->RegisterObjectProperty("Camera", "float fov", asOFFSET(CameraComponent, fov));
|
||||||
|
scriptEngine->RegisterObjectProperty("Camera", "float aspect", asOFFSET(CameraComponent, aspect));
|
||||||
|
scriptEngine->RegisterObjectProperty("Camera", "float nearZ", asOFFSET(CameraComponent, nearZ));
|
||||||
|
scriptEngine->RegisterObjectProperty("Camera", "float farZ", asOFFSET(CameraComponent, farZ));
|
||||||
|
REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "Camera", "void f()", camera_construct);
|
||||||
|
|
||||||
|
scriptEngine->RegisterObjectType("WorldCamera", sizeof(WorldCamera), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<WorldCamera>());
|
||||||
|
scriptEngine->RegisterObjectProperty("WorldCamera", "Camera camera", asOFFSET(WorldCamera, camera));
|
||||||
|
scriptEngine->RegisterObjectProperty("WorldCamera", "Transform transform", asOFFSET(WorldCamera, transform));
|
||||||
|
REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, "WorldCamera", "void f()", sceneCamera_Construct);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptSystem::registerMathFunctions() {
|
||||||
|
REGISTER_EXT_OBJECT_METHOD(scriptEngine, "vec3", "vec3 opAdd(const vec3 &in)", vec3_add);
|
||||||
|
REGISTER_EXT_OBJECT_METHOD(scriptEngine, "vec3", "vec3 opSub(const vec3 &in) const", vec3_sub);
|
||||||
|
REGISTER_EXT_OBJECT_METHOD(scriptEngine, "vec3", "vec3 opNeg() const", vec3_neg);
|
||||||
|
REGISTER_EXT_OBJECT_METHOD(scriptEngine, "vec3", "vec3 opMul(float) const", vec3_mult);
|
||||||
|
REGISTER_EXT_OBJECT_METHOD(scriptEngine, "vec3", "vec3 opMul_r(float) const", vec3_mult);
|
||||||
|
|
||||||
|
REGISTER_EXT_OBJECT_METHOD(scriptEngine, "quat", "quat opMul(const quat &in) const", quat_multiply);
|
||||||
|
REGISTER_EXT_OBJECT_METHOD(scriptEngine, "quat", "void setEuler(vec3)", quat_setEuler);
|
||||||
|
REGISTER_EXT_OBJECT_METHOD(scriptEngine, "quat", "vec3 getEuler() const", quat_getEuler);
|
||||||
|
|
||||||
|
REGISTER_EXT_OBJECT_METHOD(scriptEngine, "Transform", "vec3 relative(vec3)", transform_relative);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptSystem::registerMath() {
|
||||||
|
registerMathStructs();
|
||||||
|
registerMathFunctions();
|
||||||
|
}
|
||||||
|
} // namespace Deer
|
||||||
19
Deer/src/DeerCore/ScriptSystem/Registering.cpp
Normal file
19
Deer/src/DeerCore/ScriptSystem/Registering.cpp
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
#include "DeerCore/Log.h"
|
||||||
|
#include "DeerCore/ScriptSystem.h"
|
||||||
|
#include "DeerCore/Tools/Memory.h"
|
||||||
|
#include "angelscript.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace ScriptSystem {
|
||||||
|
extern asIScriptEngine* scriptEngine;
|
||||||
|
|
||||||
|
} // namespace ScriptSystem
|
||||||
|
|
||||||
|
asIScriptEngine* ScriptSystem::getScriptEngine() {
|
||||||
|
return scriptEngine;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace Deer
|
||||||
33
Deer/src/DeerCore/ScriptSystem/ScriptEnvironment.cpp
Normal file
33
Deer/src/DeerCore/ScriptSystem/ScriptEnvironment.cpp
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "DeerCore/Log.h"
|
||||||
|
#include "DeerCore/ScriptSystem.h"
|
||||||
|
#include "angelscript.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace ScriptSystem {
|
||||||
|
extern asIScriptEngine* scriptEngine;
|
||||||
|
}
|
||||||
|
|
||||||
|
Scope<ScriptEnvironment> ScriptSystem::createScriptEnvironment(const char* baseTypeName) {
|
||||||
|
asITypeInfo* baseType = scriptEngine->GetTypeInfoByDecl(baseTypeName);
|
||||||
|
if (!baseType) {
|
||||||
|
DEER_CORE_ERROR("Base type {} not found", baseTypeName);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (baseType->GetModule()) {
|
||||||
|
DEER_CORE_ERROR("Base type {} must be a engine type", baseTypeName);
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
Scope<ScriptEnvironment> environment = MakeScope<ScriptEnvironment>(baseType);
|
||||||
|
|
||||||
|
return environment;
|
||||||
|
}
|
||||||
|
|
||||||
|
ScriptEnvironment::ScriptEnvironment(asITypeInfo* _baseType)
|
||||||
|
: baseType(_baseType), baseTypeName(_baseType->GetName()) {
|
||||||
|
|
||||||
|
ScriptSystem::scriptEngine->GetTypedefCount();
|
||||||
|
}
|
||||||
|
} // namespace Deer
|
||||||
50
Deer/src/DeerCore/ScriptSystem/ScriptSystem.cpp
Normal file
50
Deer/src/DeerCore/ScriptSystem/ScriptSystem.cpp
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#include "DeerCore/ScriptSystem.h"
|
||||||
|
#include "DeerCore/ScriptSystem/Helpers.h"
|
||||||
|
#include "DeerCore/ScriptSystem/InternalAPI/InternalFunctions.h"
|
||||||
|
|
||||||
|
#include "angelscript.h"
|
||||||
|
#include "scriptany.h"
|
||||||
|
#include "scriptarray.h"
|
||||||
|
#include "scriptbuilder.h"
|
||||||
|
#include "scriptdictionary.h"
|
||||||
|
#include "scripthandle.h"
|
||||||
|
#include "scriptstdstring.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace ScriptSystem {
|
||||||
|
asIScriptEngine* scriptEngine;
|
||||||
|
|
||||||
|
void registerMath();
|
||||||
|
void registerEngine();
|
||||||
|
#ifdef DEER_RENDER
|
||||||
|
void registerResources();
|
||||||
|
#endif
|
||||||
|
}; // namespace ScriptSystem
|
||||||
|
|
||||||
|
void ScriptSystem::init() {
|
||||||
|
asPrepareMultithread();
|
||||||
|
|
||||||
|
scriptEngine = asCreateScriptEngine();
|
||||||
|
AS_CHECK(scriptEngine->SetMessageCallback(asFUNCTION(Deer::ScriptSystem::errorCallback_angelscript), 0, asCALL_CDECL));
|
||||||
|
REGISTER_GLOBAL_FUNC(scriptEngine, "void print(const string&in text)", print);
|
||||||
|
|
||||||
|
RegisterScriptHandle(scriptEngine);
|
||||||
|
RegisterScriptAny(scriptEngine);
|
||||||
|
RegisterStdString(scriptEngine);
|
||||||
|
RegisterScriptArray(scriptEngine, true);
|
||||||
|
RegisterScriptDictionary(scriptEngine);
|
||||||
|
|
||||||
|
registerMath();
|
||||||
|
registerEngine();
|
||||||
|
#ifdef DEER_RENDER
|
||||||
|
registerResources();
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptSystem::shutdown() {
|
||||||
|
asUnprepareMultithread();
|
||||||
|
}
|
||||||
|
} // namespace Deer
|
||||||
90
Deer/src/DeerCore/Universe/Universe.cpp
Normal file
90
Deer/src/DeerCore/Universe/Universe.cpp
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
#include "DeerCore/Universe.h"
|
||||||
|
#include "DeerCore/Log.h"
|
||||||
|
#include "DeerCore/Tools/Memory.h"
|
||||||
|
#include "DeerCore/World.h"
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace Universe {
|
||||||
|
struct WorldSlot {
|
||||||
|
Scope<World> world = nullptr;
|
||||||
|
uint32_t generation = 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<WorldSlot> universeWorldSlots;
|
||||||
|
std::mutex universeMutex;
|
||||||
|
|
||||||
|
int getFreeWorldSlot();
|
||||||
|
void unlockedFlushDestroyedWorlds();
|
||||||
|
} // namespace Universe
|
||||||
|
|
||||||
|
int Universe::getFreeWorldSlot() {
|
||||||
|
for (int i = 0; i < universeWorldSlots.size(); i++) {
|
||||||
|
if (universeWorldSlots[i].world == nullptr)
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
Universe::WorldHandle Universe::createWorld(const WorldSettings& worldSettings) {
|
||||||
|
std::lock_guard<std::mutex> lock(universeMutex);
|
||||||
|
unlockedFlushDestroyedWorlds();
|
||||||
|
|
||||||
|
int universeSlot = getFreeWorldSlot();
|
||||||
|
if (universeSlot == -1) {
|
||||||
|
universeSlot = universeWorldSlots.size();
|
||||||
|
universeWorldSlots.push_back({});
|
||||||
|
}
|
||||||
|
|
||||||
|
WorldSlot& worldSlot = universeWorldSlots[universeSlot];
|
||||||
|
worldSlot.world = MakeScope<World>(worldSettings);
|
||||||
|
|
||||||
|
return WorldHandle(universeSlot, worldSlot.generation);
|
||||||
|
}
|
||||||
|
|
||||||
|
World& Universe::getWorld(WorldHandle handle) {
|
||||||
|
std::lock_guard<std::mutex> lock(universeMutex);
|
||||||
|
|
||||||
|
DEER_CORE_ASSERT(handle.worldId < universeWorldSlots.size(), "Invalid world handle");
|
||||||
|
DEER_CORE_ASSERT(handle.generation == universeWorldSlots[handle.worldId].generation, "Invalid world generation");
|
||||||
|
DEER_CORE_ASSERT(universeWorldSlots[handle.worldId].world, "World no longer exists");
|
||||||
|
|
||||||
|
return *universeWorldSlots[handle.worldId].world;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Universe::destroyWorld(WorldHandle handle) {
|
||||||
|
std::lock_guard<std::mutex> lock(universeMutex);
|
||||||
|
|
||||||
|
DEER_CORE_ASSERT(handle.worldId < universeWorldSlots.size(), "Invalid world handle");
|
||||||
|
DEER_CORE_ASSERT(handle.generation == universeWorldSlots[handle.worldId].generation, "Invalid world generation");
|
||||||
|
DEER_CORE_ASSERT(universeWorldSlots[handle.worldId].world, "World no longer exists");
|
||||||
|
|
||||||
|
universeWorldSlots[handle.worldId].world->destroy();
|
||||||
|
unlockedFlushDestroyedWorlds();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Universe::destroyAllWorlds() {
|
||||||
|
std::lock_guard<std::mutex> lock(universeMutex);
|
||||||
|
for (WorldSlot& slot : universeWorldSlots)
|
||||||
|
slot.world->destroy();
|
||||||
|
unlockedFlushDestroyedWorlds();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Universe::unlockedFlushDestroyedWorlds() {
|
||||||
|
for (WorldSlot& slot : universeWorldSlots) {
|
||||||
|
if (slot.world != nullptr && slot.world->getExecutionState() == WorldState::ReadyToDestroy) {
|
||||||
|
slot.world.release();
|
||||||
|
slot.world = nullptr;
|
||||||
|
slot.generation++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Universe::flushDestroyedWorlds() {
|
||||||
|
std::lock_guard<std::mutex> lock(universeMutex);
|
||||||
|
unlockedFlushDestroyedWorlds();
|
||||||
|
}
|
||||||
|
} // namespace Deer
|
||||||
@ -1,6 +1,5 @@
|
|||||||
#include "DeerCore/EntityEnviroment.h"
|
#include "DeerCore/EntityEnviroment.h"
|
||||||
|
|
||||||
#include "DeerCore/Application.h"
|
|
||||||
#include "DeerCore/Components.h"
|
#include "DeerCore/Components.h"
|
||||||
#include "DeerCore/Log.h"
|
#include "DeerCore/Log.h"
|
||||||
#include "DeerRender/Render/Render.h"
|
#include "DeerRender/Render/Render.h"
|
||||||
@ -26,16 +25,16 @@ namespace Deer {
|
|||||||
createEntityWithId(0, "root");
|
createEntityWithId(0, "root");
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t EntityEnvironment::getEntityCount() const {
|
uint32_t EntityEnvironment::getEntityCount() const {
|
||||||
return entities.size() - unused_entities_spaces.size();
|
return entities.size() - unused_entities_spaces.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity& EntityEnvironment::getEntity(uint16_t id) {
|
Entity& EntityEnvironment::getEntity(uint32_t id) {
|
||||||
DEER_CORE_ASSERT(entityExists(id), "Entity id {0} does not exist", id);
|
DEER_CORE_ASSERT(entityExists(id), "Entity id {0} does not exist", id);
|
||||||
return entities[id];
|
return entities[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntityEnvironment::entityExists(uint16_t id) const {
|
bool EntityEnvironment::entityExists(uint32_t id) const {
|
||||||
if (id >= entities.size())
|
if (id >= entities.size())
|
||||||
return false;
|
return false;
|
||||||
const Entity& refEntity = entities[id];
|
const Entity& refEntity = entities[id];
|
||||||
@ -67,7 +66,7 @@ namespace Deer {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
Entity& EntityEnvironment::createEntityWithId(uint16_t id, const std::string& name) {
|
Entity& EntityEnvironment::createEntityWithId(uint32_t id, const std::string& name) {
|
||||||
entt::entity entityID = m_registry->create();
|
entt::entity entityID = m_registry->create();
|
||||||
|
|
||||||
// We allocate all the memory until that id
|
// We allocate all the memory until that id
|
||||||
@ -118,7 +117,7 @@ namespace Deer {
|
|||||||
return entity;
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityEnvironment::destroyEntity(uint16_t entityID) {
|
void EntityEnvironment::destroyEntity(uint32_t entityID) {
|
||||||
DEER_CORE_ASSERT(entityExists(entityID), "Entity id {0} does not exist", entityID);
|
DEER_CORE_ASSERT(entityExists(entityID), "Entity id {0} does not exist", entityID);
|
||||||
DEER_CORE_ASSERT(entityID != 0, "Cannot destroy root");
|
DEER_CORE_ASSERT(entityID != 0, "Cannot destroy root");
|
||||||
|
|
||||||
@ -128,7 +127,7 @@ namespace Deer {
|
|||||||
RelationshipComponent& relationship = entity.getComponent<RelationshipComponent>();
|
RelationshipComponent& relationship = entity.getComponent<RelationshipComponent>();
|
||||||
// We want to delete all childrens
|
// We want to delete all childrens
|
||||||
for (int i = 0; i < relationship.getChildCount(); i++) {
|
for (int i = 0; i < relationship.getChildCount(); i++) {
|
||||||
uint16_t childID = relationship.getChildId(i);
|
uint32_t childID = relationship.getChildId(i);
|
||||||
destroyEntity(childID);
|
destroyEntity(childID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -26,10 +26,10 @@ namespace Deer {
|
|||||||
template <class Archive>
|
template <class Archive>
|
||||||
void save(Archive& archive, EntityEnvironmentEntity const& m_entities) {
|
void save(Archive& archive, EntityEnvironmentEntity const& m_entities) {
|
||||||
archive(cereal::make_size_tag(static_cast<cereal::size_type>(
|
archive(cereal::make_size_tag(static_cast<cereal::size_type>(
|
||||||
m_entities.environment.getEntityCount())));
|
m_entities.entityEnvironment->getEntityCount())));
|
||||||
|
|
||||||
for (uint16_t i = 0; i < m_entities.environment.getEntityCount(); i++) {
|
for (uint16_t i = 0; i < m_entities.entityEnvironment->getEntityCount(); i++) {
|
||||||
while (!m_entities.environment.entityExists(i)) {
|
while (!m_entities.entityEnvironment->entityExists(i)) {
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,6 @@
|
|||||||
#include "DeerCore/EntityEnviroment.h"
|
#include "DeerCore/EntityEnviroment.h"
|
||||||
#include "DeerCore/Log.h"
|
#include "DeerCore/Log.h"
|
||||||
#include "DeerCore/Tools/Memory.h"
|
#include "DeerCore/Tools/Memory.h"
|
||||||
#include "DeerCore/World/WorldData.h"
|
|
||||||
|
|
||||||
#ifdef DEER_RENDER
|
#ifdef DEER_RENDER
|
||||||
#include "DeerRender/FrameBuffer.h"
|
#include "DeerRender/FrameBuffer.h"
|
||||||
@ -13,32 +12,31 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
void World::clear() {
|
World::World(const WorldSettings& settings) : worldSettings(settings) {
|
||||||
environment.clear();
|
entityEnvironment = MakeScope<EntityEnvironment>();
|
||||||
|
DEER_CORE_ASSERT(worldSettings.updateFrequency <= 120, "Invalid world update frequency");
|
||||||
|
|
||||||
#ifdef DEER_RENDER
|
executingState = WorldState::Stopped;
|
||||||
ResourceManager<Shader>::unloadResources();
|
|
||||||
ResourceManager<GPUMesh>::unloadResources();
|
|
||||||
ResourceManager<FrameBuffer>::unloadResources();
|
|
||||||
ResourceManager<Texture>::unloadResources();
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool World::getExecutingState() {
|
World::~World() {
|
||||||
return isExecuting;
|
DEER_CORE_ASSERT(executingState == WorldState::Stopped, "Invalid executing state while destroying world");
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::initExecution() {
|
void World::stopExecution() {
|
||||||
DEER_CORE_ASSERT(!isExecuting, "Deer scene is already executing");
|
if (executingState == WorldState::Executing)
|
||||||
isExecuting = true;
|
executingState = WorldState::StopRequested;
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::tickExecution() {
|
void World::destroy() {
|
||||||
|
if (executingState == WorldState::Executing || executingState == WorldState::StopRequested)
|
||||||
|
executingState = WorldState::DestroyQueued;
|
||||||
|
else
|
||||||
|
executingState = WorldState::ReadyToDestroy;
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::endExecution() {
|
WorldState World::getExecutionState() {
|
||||||
DEER_CORE_ASSERT(isExecuting, "Deer scene is not executing");
|
return executingState;
|
||||||
isExecuting = false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
|
|||||||
@ -1,10 +0,0 @@
|
|||||||
#include "DeerCore/EntityEnviroment.h"
|
|
||||||
#include "DeerCore/Tools/Memory.h"
|
|
||||||
|
|
||||||
namespace Deer {
|
|
||||||
namespace World {
|
|
||||||
EntityEnvironment environment;
|
|
||||||
bool isExecuting = false;
|
|
||||||
} // namespace World
|
|
||||||
|
|
||||||
} // namespace Deer
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include "DeerCore/Tools/Memory.h"
|
|
||||||
|
|
||||||
namespace Deer {
|
|
||||||
class EntityEnvironment;
|
|
||||||
|
|
||||||
namespace World {
|
|
||||||
extern EntityEnvironment environment;
|
|
||||||
extern bool isExecuting;
|
|
||||||
} // namespace World
|
|
||||||
|
|
||||||
} // namespace Deer
|
|
||||||
@ -1,80 +0,0 @@
|
|||||||
#include "DeerRender/Application.h"
|
|
||||||
#include <functional>
|
|
||||||
#include <thread>
|
|
||||||
|
|
||||||
#include "DeerRender/Render/Render.h"
|
|
||||||
#include "DeerRender/Render/RenderCommand.h"
|
|
||||||
|
|
||||||
#include "DeerRender/Log.h"
|
|
||||||
|
|
||||||
#include "DeerRender/ImGui/ImGuiLayer.h"
|
|
||||||
#include "imgui.h"
|
|
||||||
|
|
||||||
namespace Deer {
|
|
||||||
namespace Application {
|
|
||||||
Function renderCallback;
|
|
||||||
EventFunction eventCallback;
|
|
||||||
Scope<Window> window;
|
|
||||||
Scope<ImGuiLayer> imGuiLayer;
|
|
||||||
|
|
||||||
void setRenderCallback(Function _render) {
|
|
||||||
renderCallback = _render;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setEventCallback(EventFunction _event) {
|
|
||||||
eventCallback = _event;
|
|
||||||
}
|
|
||||||
|
|
||||||
Window& getWindow() {
|
|
||||||
return *window;
|
|
||||||
}
|
|
||||||
|
|
||||||
void internalEventCallback(Event& e) {
|
|
||||||
if (eventCallback)
|
|
||||||
eventCallback(e);
|
|
||||||
|
|
||||||
imGuiLayer->onEvent(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
void initWindow() {
|
|
||||||
window = Scope<Window>(Window::create());
|
|
||||||
|
|
||||||
window->setEventCallback(Deer::Application::internalEventCallback);
|
|
||||||
window->initWindow();
|
|
||||||
|
|
||||||
imGuiLayer = MakeScope<ImGuiLayer>();
|
|
||||||
imGuiLayer->onAttach();
|
|
||||||
|
|
||||||
RenderCommand::init();
|
|
||||||
}
|
|
||||||
|
|
||||||
void resolveEvents() {
|
|
||||||
window->resolveEvents();
|
|
||||||
}
|
|
||||||
|
|
||||||
void shutdownWindow() {
|
|
||||||
imGuiLayer->onDetach();
|
|
||||||
|
|
||||||
imGuiLayer.reset();
|
|
||||||
window.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
void runRender(float deltaTime) {
|
|
||||||
if (!renderCallback)
|
|
||||||
return;
|
|
||||||
|
|
||||||
RenderCommand::setClearColor({0.2f, 0.2f, 0.3f, 1.0f});
|
|
||||||
RenderCommand::clear();
|
|
||||||
|
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
|
||||||
io.DeltaTime = (float)deltaTime;
|
|
||||||
imGuiLayer->begin();
|
|
||||||
|
|
||||||
renderCallback();
|
|
||||||
|
|
||||||
imGuiLayer->end();
|
|
||||||
window->onRender();
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace Application
|
|
||||||
} // namespace Deer
|
|
||||||
107
Deer/src/DeerRender/Core/Engine.cpp
Normal file
107
Deer/src/DeerRender/Core/Engine.cpp
Normal file
@ -0,0 +1,107 @@
|
|||||||
|
#ifdef DEER_RENDER
|
||||||
|
#include "DeerRender/Engine.h"
|
||||||
|
#include "DeerRender/Log.h"
|
||||||
|
|
||||||
|
#include "DeerRender/ImGui/ImGuiLayer.h"
|
||||||
|
#include "DeerRender/ScriptSystem.h"
|
||||||
|
#include "DeerRender/Universe.h"
|
||||||
|
#include "DeerRender/Window.h"
|
||||||
|
#include "DeerRender/World.h"
|
||||||
|
#include "imgui.h"
|
||||||
|
|
||||||
|
#include "DeerRender/Render/RenderCommand.h"
|
||||||
|
#include "DeerRender/Render/RenderUtils.h"
|
||||||
|
|
||||||
|
#include "DeerRender/FrameBuffer.h"
|
||||||
|
#include "DeerRender/Mesh.h"
|
||||||
|
#include "DeerRender/Resource.h"
|
||||||
|
#include "DeerRender/Shader.h"
|
||||||
|
#include "DeerRender/Texture.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace Engine {
|
||||||
|
Function renderCallback = nullptr;
|
||||||
|
Function updateCallback = nullptr;
|
||||||
|
EventFunction eventCallback;
|
||||||
|
|
||||||
|
Scope<Window> window = nullptr;
|
||||||
|
Scope<ImGuiLayer> imGuiLayer = nullptr;
|
||||||
|
bool running = true;
|
||||||
|
|
||||||
|
void internalEventCallback(Event& e);
|
||||||
|
void runRender(float);
|
||||||
|
} // namespace Engine
|
||||||
|
|
||||||
|
Window& Engine::getWindow() {
|
||||||
|
return *window;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::setEventCallback(EventFunction _event) {
|
||||||
|
eventCallback = _event;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::setUpdateCallback(Function _update) {
|
||||||
|
updateCallback = _update;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::setRenderCallback(Function _render) {
|
||||||
|
renderCallback = _render;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::internalEventCallback(Event& e) {
|
||||||
|
if (eventCallback)
|
||||||
|
eventCallback(e);
|
||||||
|
|
||||||
|
imGuiLayer->onEvent(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::init() {
|
||||||
|
Log::init();
|
||||||
|
ScriptSystem::init();
|
||||||
|
|
||||||
|
imGuiLayer = MakeScope<ImGuiLayer>();
|
||||||
|
|
||||||
|
window = Scope<Window>(Window::create());
|
||||||
|
window->setEventCallback(Engine::internalEventCallback);
|
||||||
|
window->initWindow();
|
||||||
|
|
||||||
|
RenderCommand::init();
|
||||||
|
RenderUtils::initializeRenderUtils();
|
||||||
|
|
||||||
|
imGuiLayer = MakeScope<ImGuiLayer>();
|
||||||
|
imGuiLayer->onAttach(*window);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::shutdown() {
|
||||||
|
Universe::destroyAllWorlds();
|
||||||
|
|
||||||
|
ResourceManager<Shader>::unloadResources();
|
||||||
|
ResourceManager<GPUMesh>::unloadResources();
|
||||||
|
ResourceManager<FrameBuffer>::unloadResources();
|
||||||
|
ResourceManager<Texture>::unloadResources();
|
||||||
|
|
||||||
|
imGuiLayer->onDetach();
|
||||||
|
imGuiLayer.reset();
|
||||||
|
window.reset();
|
||||||
|
|
||||||
|
ScriptSystem::shutdown();
|
||||||
|
RenderUtils::deinitializeRenderUtils();
|
||||||
|
Log::shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::beginRender() {
|
||||||
|
RenderCommand::setClearColor({0.2f, 0.2f, 0.3f, 1.0f});
|
||||||
|
RenderCommand::clear();
|
||||||
|
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
io.DeltaTime = 1.0f / 60;
|
||||||
|
imGuiLayer->begin();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Engine::endRender() {
|
||||||
|
imGuiLayer->end();
|
||||||
|
window->onRender();
|
||||||
|
window->resolveEvents();
|
||||||
|
}
|
||||||
|
} // namespace Deer
|
||||||
|
#endif
|
||||||
@ -1,18 +1,19 @@
|
|||||||
#include "DeerRender/Input.h"
|
#include "DeerRender/Input.h"
|
||||||
#include "DeerRender/Application.h"
|
#include "DeerRender/Engine.h"
|
||||||
|
#include "DeerRender/Window.h"
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
#ifdef DEER_RENDER
|
#ifdef DEER_RENDER
|
||||||
bool Input::isKeyPressed(unsigned int key) {
|
bool Input::isKeyPressed(unsigned int key) {
|
||||||
return Application::getWindow().getKeyPressed(key);
|
return Engine::getWindow().getKeyPressed(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Input::isMouseButtonPressed(int button) {
|
bool Input::isMouseButtonPressed(int button) {
|
||||||
return Application::getWindow().getMouseButton(button);
|
return Engine::getWindow().getMouseButton(button);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Input::getMousePos(float& x, float& y) {
|
void Input::getMousePos(float& x, float& y) {
|
||||||
return Application::getWindow().getMousePos(x, y);
|
return Engine::getWindow().getMousePos(x, y);
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
bool Input::isKeyPressed(unsigned int key) {
|
bool Input::isKeyPressed(unsigned int key) {
|
||||||
@ -4,17 +4,20 @@
|
|||||||
#include "DeerRender/Events/MouseEvent.h"
|
#include "DeerRender/Events/MouseEvent.h"
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
|
class Window;
|
||||||
|
|
||||||
class ImGuiLayer {
|
class ImGuiLayer {
|
||||||
public:
|
public:
|
||||||
~ImGuiLayer() = default;
|
~ImGuiLayer() = default;
|
||||||
|
|
||||||
void onAttach();
|
void onAttach(Window& window);
|
||||||
void onDetach();
|
void onDetach();
|
||||||
|
|
||||||
void begin();
|
void begin();
|
||||||
void end();
|
void end();
|
||||||
|
|
||||||
void onEvent(Event& event);
|
void onEvent(Event& event);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool onMouseButtonPressedEvent(MouseButtonPressedEvent& e);
|
bool onMouseButtonPressedEvent(MouseButtonPressedEvent& e);
|
||||||
bool onMouseButtonReleasedEvent(MouseButtonReleasedEvent& e);
|
bool onMouseButtonReleasedEvent(MouseButtonReleasedEvent& e);
|
||||||
@ -25,5 +28,4 @@ namespace Deer {
|
|||||||
bool onKeyTypedEvent(KeyTypedEvent& e);
|
bool onKeyTypedEvent(KeyTypedEvent& e);
|
||||||
bool onWindowResizeEvent(WindowResizeEvent& e);
|
bool onWindowResizeEvent(WindowResizeEvent& e);
|
||||||
};
|
};
|
||||||
}
|
} // namespace Deer
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
#include "DeerRender/DataStore.h"
|
|
||||||
#include "DeerRender/Log.h"
|
#include "DeerRender/Log.h"
|
||||||
#include "DeerRender/Mesh.h"
|
#include "DeerRender/Mesh.h"
|
||||||
#include "DeerRender/Render/VertexArray.h"
|
#include "DeerRender/Render/VertexArray.h"
|
||||||
|
|||||||
79
Deer/src/DeerRender/ScriptSystem/InternalAPI/Resources.cpp
Normal file
79
Deer/src/DeerRender/ScriptSystem/InternalAPI/Resources.cpp
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
#include "DeerRender/ScriptSystem/InternalAPI/Resources.h"
|
||||||
|
#include "DeerRender/ScriptSystem.h"
|
||||||
|
|
||||||
|
#include "DeerRender/Log.h"
|
||||||
|
#include "DeerRender/Tools/Path.h"
|
||||||
|
|
||||||
|
#include "angelscript.h"
|
||||||
|
#include "scriptarray.h"
|
||||||
|
#include "scriptstdstring.h"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace ScriptSystem {
|
||||||
|
extern asIScriptEngine* scriptEngine;
|
||||||
|
|
||||||
|
ResourceType getResourceType(std::string& dir) {
|
||||||
|
Path path(dir);
|
||||||
|
std::string extension = path.extension().string();
|
||||||
|
|
||||||
|
if (extension == ".obj" || extension == ".fbx" || extension == ".dae" ||
|
||||||
|
extension == ".3ds" || extension == ".ply" || extension == ".stl" ||
|
||||||
|
extension == ".glb" || extension == ".gltf" || extension == ".mtl") {
|
||||||
|
return ResourceType::MESH;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (extension == ".glsl")
|
||||||
|
return ResourceType::SHADER;
|
||||||
|
|
||||||
|
if (extension == ".png")
|
||||||
|
return ResourceType::TEXTURE;
|
||||||
|
|
||||||
|
return ResourceType::NONE;
|
||||||
|
};
|
||||||
|
|
||||||
|
CScriptArray* getResourceFolders(std::string& path_s) {
|
||||||
|
asITypeInfo* arrayString = scriptEngine->GetTypeInfoByName("array<string>");
|
||||||
|
CScriptArray* array = CScriptArray::Create(arrayString);
|
||||||
|
|
||||||
|
Path path_p = Path("Resources") / Path(path_s).lexically_normal();
|
||||||
|
try {
|
||||||
|
for (const auto& entry : std::filesystem::directory_iterator(path_p)) {
|
||||||
|
if (entry.is_directory()) {
|
||||||
|
std::string s = entry.path().lexically_relative("Resources").string();
|
||||||
|
|
||||||
|
array->Resize(array->GetSize() + 1);
|
||||||
|
array->SetValue(array->GetSize() - 1, &s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
DEER_EDITOR_ENGINE_ERROR("Error in getResourceFolders(), {}", e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
CScriptArray* getResourceFiles(std::string& path_s) {
|
||||||
|
asITypeInfo* arrayString = scriptEngine->GetTypeInfoByName("array<string>");
|
||||||
|
CScriptArray* array = CScriptArray::Create(arrayString);
|
||||||
|
|
||||||
|
Path path_p = Path("Resources") / Path(path_s).lexically_normal();
|
||||||
|
try {
|
||||||
|
for (const auto& entry : std::filesystem::directory_iterator(path_p)) {
|
||||||
|
if (entry.is_regular_file()) {
|
||||||
|
std::string s = entry.path().lexically_relative("Resources").string();
|
||||||
|
|
||||||
|
array->Resize(array->GetSize() + 1);
|
||||||
|
array->SetValue(array->GetSize() - 1, &s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (const std::exception& e) {
|
||||||
|
DEER_EDITOR_ENGINE_ERROR("Error in getResourceFiles(), {}", e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
return array;
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace ScriptSystem
|
||||||
|
} // namespace Deer
|
||||||
32
Deer/src/DeerRender/ScriptSystem/InternalAPI/Resources.h
Normal file
32
Deer/src/DeerRender/ScriptSystem/InternalAPI/Resources.h
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "scriptarray.h"
|
||||||
|
#include "scriptdictionary.h"
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace ScriptSystem {
|
||||||
|
template <typename T>
|
||||||
|
std::string resource_getPath(Resource<T> resource) {
|
||||||
|
return ResourceManager<T>::getStorageId(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
std::string resource_getName(Resource<T> resource) {
|
||||||
|
return ResourceManager<T>::getStorageId(resource).stem().string();
|
||||||
|
}
|
||||||
|
|
||||||
|
enum ResourceType : uint32_t {
|
||||||
|
NONE = 0,
|
||||||
|
MESH = 1,
|
||||||
|
SHADER = 2,
|
||||||
|
TEXTURE = 3,
|
||||||
|
};
|
||||||
|
|
||||||
|
CScriptArray* getResourceFolders(std::string& path);
|
||||||
|
CScriptArray* getResourceFiles(std::string& path);
|
||||||
|
|
||||||
|
ResourceType getResourceType(std::string&);
|
||||||
|
} // namespace ScriptSystem
|
||||||
|
} // namespace Deer
|
||||||
60
Deer/src/DeerRender/ScriptSystem/ResourcesRegistry.cpp
Normal file
60
Deer/src/DeerRender/ScriptSystem/ResourcesRegistry.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#include "DeerCore/ScriptSystem/Helpers.h"
|
||||||
|
#include "DeerRender/ScriptSystem.h"
|
||||||
|
#include "DeerRender/ScriptSystem/InternalAPI/Resources.h"
|
||||||
|
|
||||||
|
#include "DeerRender/Mesh.h"
|
||||||
|
#include "DeerRender/Resource.h"
|
||||||
|
#include "DeerRender/Shader.h"
|
||||||
|
#include "DeerRender/Texture.h"
|
||||||
|
#include "angelscript.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace ScriptSystem {
|
||||||
|
extern asIScriptEngine* scriptEngine;
|
||||||
|
|
||||||
|
void registerResources();
|
||||||
|
|
||||||
|
void registerResourceStructs();
|
||||||
|
void registerResourceFunctions();
|
||||||
|
|
||||||
|
template <class T>
|
||||||
|
void registerResourceBasics(const char* objName) {
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, objName, "bool isValid() const", Resource<T>, isValid);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, objName, "int get_resourceId() const property", Resource<T>, getResourceId);
|
||||||
|
REGISTER_EXT_OBJECT_METHOD(scriptEngine, objName, "string get_name() const property", resource_getName);
|
||||||
|
REGISTER_EXT_OBJECT_METHOD(scriptEngine, objName, "string get_path() const property", resource_getPath);
|
||||||
|
}
|
||||||
|
} // namespace ScriptSystem
|
||||||
|
|
||||||
|
void ScriptSystem::registerResourceStructs() {
|
||||||
|
AS_CHECK(scriptEngine->RegisterObjectType("GPUMesh", sizeof(Resource<GPUMesh>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits<Resource<GPUMesh>>()));
|
||||||
|
AS_CHECK(scriptEngine->RegisterObjectType("Shader", sizeof(Resource<Shader>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits<Resource<Shader>>()));
|
||||||
|
AS_CHECK(scriptEngine->RegisterObjectType("Texture", sizeof(Resource<Texture>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits<Resource<Texture>>()));
|
||||||
|
|
||||||
|
scriptEngine->RegisterEnum("ResourceType");
|
||||||
|
scriptEngine->RegisterEnumValue("ResourceType", "None", (int)ResourceType::NONE);
|
||||||
|
scriptEngine->RegisterEnumValue("ResourceType", "Mesh", (int)ResourceType::MESH);
|
||||||
|
scriptEngine->RegisterEnumValue("ResourceType", "Shader", (int)ResourceType::SHADER);
|
||||||
|
scriptEngine->RegisterEnumValue("ResourceType", "Texture", (int)ResourceType::TEXTURE);
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
void ScriptSystem::registerResourceFunctions() {
|
||||||
|
scriptEngine->SetDefaultNamespace("Resource");
|
||||||
|
REGISTER_GLOBAL_FUNC("GPUMesh loadGPUMesh(string&in path)", ResourceManager<GPUMesh>::loadResource<ResourceDataSource>);
|
||||||
|
REGISTER_GLOBAL_FUNC("Shader loadShader(string&in path)", ResourceManager<Shader>::loadResource<ResourceDataSource>);
|
||||||
|
REGISTER_GLOBAL_FUNC("Texture loadTexture(string&in path)", ResourceManager<Texture>::loadResource<ResourceDataSource>);
|
||||||
|
|
||||||
|
REGISTER_GLOBAL_FUNC("array<string>@ getResourceFolders(string&in path)", StudioAPI::getResourceFolders);
|
||||||
|
REGISTER_GLOBAL_FUNC("array<string>@ getResourceFiles(string&in path)", StudioAPI::getResourceFiles);
|
||||||
|
REGISTER_GLOBAL_FUNC("ResourceType getResourceType(string&in path)", StudioAPI::getResourceType);
|
||||||
|
scriptEngine->SetDefaultNamespace("");
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
void ScriptSystem::registerResources() {
|
||||||
|
registerResourceStructs();
|
||||||
|
registerResourceBasics<GPUMesh>("GPUMesh");
|
||||||
|
registerResourceBasics<Shader>("Shader");
|
||||||
|
registerResourceBasics<Texture>("Texture");
|
||||||
|
}
|
||||||
|
} // namespace Deer
|
||||||
@ -1,4 +1,3 @@
|
|||||||
#include "DeerRender/DataStore.h"
|
|
||||||
#include "DeerRender/Shader.h"
|
#include "DeerRender/Shader.h"
|
||||||
#include "DeerRender/Tools/Memory.h"
|
#include "DeerRender/Tools/Memory.h"
|
||||||
|
|
||||||
|
|||||||
@ -1,8 +1,5 @@
|
|||||||
#include "DeerRender/EntityEnviroment.h"
|
|
||||||
|
|
||||||
#include "DeerRender/Application.h"
|
|
||||||
|
|
||||||
#include "DeerRender/Components.h"
|
#include "DeerRender/Components.h"
|
||||||
|
#include "DeerRender/EntityEnviroment.h"
|
||||||
|
|
||||||
#include "DeerRender/Mesh.h"
|
#include "DeerRender/Mesh.h"
|
||||||
#include "DeerRender/Render/Render.h"
|
#include "DeerRender/Render/Render.h"
|
||||||
|
|||||||
@ -6,24 +6,50 @@
|
|||||||
#include "DeerRender/World.h"
|
#include "DeerRender/World.h"
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
void World::render() {
|
void World::execute() {
|
||||||
uint32_t mainCamera = environment.tryGetMainCamera();
|
if (executingState != WorldState::Created)
|
||||||
if (mainCamera == 0)
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Entity& m_cameraEntity = environment.getEntity(mainCamera);
|
if (worldSettings.updateFrequency == 0)
|
||||||
WorldCamera sceneCamera;
|
return;
|
||||||
sceneCamera.camera = m_cameraEntity.getComponent<CameraComponent>();
|
|
||||||
sceneCamera.transform = m_cameraEntity.getComponent<TransformComponent>();
|
|
||||||
|
|
||||||
World::render(sceneCamera);
|
auto previousTime = std::chrono::high_resolution_clock::now();
|
||||||
|
double accumulatedUpdateTime = 0.0;
|
||||||
|
double accumulatedRenderTime = 0.0;
|
||||||
|
|
||||||
|
double targetUpdateTime = 1.0f / worldSettings.updateFrequency;
|
||||||
|
double targetRenderTime = 0;
|
||||||
|
if (worldSettings.renderFrequency > 0)
|
||||||
|
targetRenderTime = 1.0f / worldSettings.renderFrequency;
|
||||||
|
|
||||||
|
executingState = WorldState::Executing;
|
||||||
|
while (executingState == WorldState::Executing) {
|
||||||
|
auto currentTime = std::chrono::high_resolution_clock::now();
|
||||||
|
std::chrono::duration<double> deltaTime = currentTime - previousTime;
|
||||||
|
previousTime = currentTime;
|
||||||
|
|
||||||
|
accumulatedUpdateTime += deltaTime.count();
|
||||||
|
accumulatedRenderTime += deltaTime.count();
|
||||||
|
|
||||||
|
while (accumulatedUpdateTime >= targetUpdateTime) {
|
||||||
|
accumulatedUpdateTime -= targetUpdateTime;
|
||||||
|
|
||||||
|
worldSettings.updateCallback(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
void World::render(const WorldCamera& sceneCamera) {
|
if (targetRenderTime > 0 && accumulatedRenderTime >= targetRenderTime) {
|
||||||
RenderCommand::setDepthBuffer(true);
|
worldSettings.renderCallback(*this);
|
||||||
environment.render(sceneCamera);
|
while (accumulatedRenderTime >= targetRenderTime)
|
||||||
|
accumulatedRenderTime -= targetRenderTime;
|
||||||
|
}
|
||||||
|
|
||||||
RenderCommand::setDepthBuffer(false);
|
std::this_thread::sleep_for(std::chrono::milliseconds(1));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (executingState == WorldState::DestroyQueued)
|
||||||
|
executingState = WorldState::ReadyToDestroy;
|
||||||
|
else
|
||||||
|
executingState = WorldState::Stopped;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
|
|||||||
@ -1,10 +1,10 @@
|
|||||||
#include "DeerRender/ImGui/ImGuiLayer.h"
|
#include "DeerRender/ImGui/ImGuiLayer.h"
|
||||||
|
|
||||||
#include "DeerRender/Application.h"
|
|
||||||
#include "DeerRender/Events/Event.h"
|
#include "DeerRender/Events/Event.h"
|
||||||
#include "DeerRender/Input.h"
|
#include "DeerRender/Input.h"
|
||||||
#include "DeerRender/Log.h"
|
#include "DeerRender/Log.h"
|
||||||
#include "DeerRender/Render/RenderCommand.h"
|
#include "DeerRender/Render/RenderCommand.h"
|
||||||
|
#include "DeerRender/Window.h"
|
||||||
|
|
||||||
// THIS ORDER
|
// THIS ORDER
|
||||||
#include "Plattform/OpenGL/imgui_impl_opengl3.h"
|
#include "Plattform/OpenGL/imgui_impl_opengl3.h"
|
||||||
@ -20,7 +20,7 @@
|
|||||||
#include "ImGuizmo.h"
|
#include "ImGuizmo.h"
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
void ImGuiLayer::onAttach() {
|
void ImGuiLayer::onAttach(Window& window) {
|
||||||
ImGui::CreateContext();
|
ImGui::CreateContext();
|
||||||
ImGui::StyleColorsDark();
|
ImGui::StyleColorsDark();
|
||||||
|
|
||||||
@ -30,11 +30,9 @@ namespace Deer {
|
|||||||
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_Init("#version 410");
|
ImGui_ImplOpenGL3_Init("#version 410");
|
||||||
Application::getWindow().initImGUI();
|
window.initImGUI();
|
||||||
|
|
||||||
io.DisplaySize =
|
io.DisplaySize = ImVec2(window.getWitdth(), window.getHeight());
|
||||||
ImVec2(Application::getWindow().getWitdth(),
|
|
||||||
Application::getWindow().getHeight());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGuiLayer::onDetach() {}
|
void ImGuiLayer::onDetach() {}
|
||||||
@ -114,13 +112,11 @@ namespace Deer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ImGuiLayer::onKeyReleasedEvent(KeyReleasedEvent& e) {
|
bool ImGuiLayer::onKeyReleasedEvent(KeyReleasedEvent& e) {
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
io.AddKeyEvent((ImGuiKey)e.getKeyCode(),
|
io.AddKeyEvent((ImGuiKey)e.getKeyCode(),
|
||||||
ImGui::IsKeyPressed(ImGuiKey_LeftSuper) || ImGui::IsKeyPressed(ImGuiKey_RightSuper));
|
ImGui::IsKeyPressed(ImGuiKey_LeftSuper) || ImGui::IsKeyPressed(ImGuiKey_RightSuper));
|
||||||
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
#include "LinuxWindow.h"
|
#include "LinuxWindow.h"
|
||||||
#include "DeerCore/Application.h"
|
|
||||||
#include "DeerCore/Log.h"
|
#include "DeerCore/Log.h"
|
||||||
|
|
||||||
#include "glad/glad.h"
|
#include "glad/glad.h"
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#include "OpenGLFrameBuffer.h"
|
#include "OpenGLFrameBuffer.h"
|
||||||
#include "DeerRender/Application.h"
|
#include "DeerRender/Engine.h"
|
||||||
#include "DeerRender/Log.h"
|
#include "DeerRender/Log.h"
|
||||||
|
#include "DeerRender/Window.h"
|
||||||
|
|
||||||
#include "glad/glad.h"
|
#include "glad/glad.h"
|
||||||
|
|
||||||
@ -30,8 +31,8 @@ namespace Deer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLFrameBuffer::unbind() {
|
void OpenGLFrameBuffer::unbind() {
|
||||||
unsigned int width = Application::getWindow().getWitdth();
|
unsigned int width = Engine::getWindow().getWitdth();
|
||||||
unsigned int height = Application::getWindow().getHeight();
|
unsigned int height = Engine::getWindow().getHeight();
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#include "OpenGLRenderAPI.h"
|
#include "OpenGLRenderAPI.h"
|
||||||
#include "DeerRender/Application.h"
|
#include "DeerRender/Engine.h"
|
||||||
#include "DeerRender/Render/VertexArray.h"
|
#include "DeerRender/Render/VertexArray.h"
|
||||||
|
#include "DeerRender/Window.h"
|
||||||
#include "Plattform/OpenGL/OpenGLBuffer.h"
|
#include "Plattform/OpenGL/OpenGLBuffer.h"
|
||||||
|
|
||||||
#include "glad/glad.h"
|
#include "glad/glad.h"
|
||||||
@ -62,8 +63,8 @@ namespace Deer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void OpenGLRenderAPI::unbindFrameBuffer() {
|
void OpenGLRenderAPI::unbindFrameBuffer() {
|
||||||
unsigned int width = Application::getWindow().getWitdth();
|
unsigned int width = Engine::getWindow().getWitdth();
|
||||||
unsigned int height = Application::getWindow().getHeight();
|
unsigned int height = Engine::getWindow().getHeight();
|
||||||
glViewport(0, 0, width, height);
|
glViewport(0, 0, width, height);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ class CScriptBuilder;
|
|||||||
class asIScriptGeneric;
|
class asIScriptGeneric;
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace AngelScriptEngine {
|
namespace StudioAPI {
|
||||||
void initialize();
|
void initialize();
|
||||||
void update();
|
void update();
|
||||||
void shutdown();
|
void shutdown();
|
||||||
@ -149,5 +149,5 @@ namespace Deer {
|
|||||||
void registerStructs();
|
void registerStructs();
|
||||||
void registerFunctions();
|
void registerFunctions();
|
||||||
void extractBaseTypes();
|
void extractBaseTypes();
|
||||||
} // namespace AngelScriptEngine
|
} // namespace StudioAPI
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
15
DeerStudio/headers/DeerStudio/StudioAPI.h
Normal file
15
DeerStudio/headers/DeerStudio/StudioAPI.h
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "DeerRender/ScriptSystem.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace StudioAPI {
|
||||||
|
extern ScriptSystem::Registry* engineRegistry;
|
||||||
|
extern ScriptSystem::Registry* uiRegistry;
|
||||||
|
extern ScriptSystem::Registry* entityRegistry;
|
||||||
|
|
||||||
|
extern ScriptSystem::Registry* mathRegistry;
|
||||||
|
extern ScriptSystem::Registry* resourceRegistry;
|
||||||
|
|
||||||
|
void registerStudioAPI();
|
||||||
|
} // namespace StudioAPI
|
||||||
|
} // namespace Deer
|
||||||
@ -22,6 +22,5 @@ namespace Deer {
|
|||||||
FrameBufferStruct getFrameBuffer(std::string& name);
|
FrameBufferStruct getFrameBuffer(std::string& name);
|
||||||
|
|
||||||
void frameBuffer_constructor(FrameBufferHandleStruct* mem);
|
void frameBuffer_constructor(FrameBufferHandleStruct* mem);
|
||||||
|
|
||||||
} // namespace StudioAPI
|
} // namespace StudioAPI
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
@ -18,7 +18,7 @@ namespace Deer {
|
|||||||
int32_t environmentId;
|
int32_t environmentId;
|
||||||
|
|
||||||
bool assertEntity(const char* funcName);
|
bool assertEntity(const char* funcName);
|
||||||
EntityEnvironment* getEntityEntityEnvironment();
|
EntityEnvironment* getEntityEnvironment();
|
||||||
};
|
};
|
||||||
|
|
||||||
struct FrameBufferHandleStruct {
|
struct FrameBufferHandleStruct {
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
#include "DeerStudio/AngelScriptEngine.h"
|
#include "DeerStudio/AngelScriptEngine.h"
|
||||||
#include "DeerStudio/AngelScriptEngine/AngelScriptRegisters.h"
|
#include "DeerStudio/AngelScriptEngine/AngelScriptRegisters.h"
|
||||||
#include "DeerStudio/AngelScriptEngine/ErrorHandle.h"
|
#include "DeerStudio/AngelScriptEngine/ErrorHandle.h"
|
||||||
|
#include "DeerStudio/StudioAPI/Resources.h"
|
||||||
|
|
||||||
#include "DeerStudio/StudioAPI/Debug.h"
|
#include "DeerStudio/StudioAPI/Debug.h"
|
||||||
|
|
||||||
@ -14,7 +15,7 @@
|
|||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
// GLOBAL DECLARATIONS
|
// GLOBAL DECLARATIONS
|
||||||
namespace AngelScriptEngine {
|
namespace StudioAPI {
|
||||||
asIScriptEngine* scriptEngine;
|
asIScriptEngine* scriptEngine;
|
||||||
asIScriptContext* scriptContext;
|
asIScriptContext* scriptContext;
|
||||||
|
|
||||||
@ -27,14 +28,14 @@ namespace Deer {
|
|||||||
asITypeInfo* panelBaseType;
|
asITypeInfo* panelBaseType;
|
||||||
asITypeInfo* serviceBaseType;
|
asITypeInfo* serviceBaseType;
|
||||||
asITypeInfo* arrayStringBaseType;
|
asITypeInfo* arrayStringBaseType;
|
||||||
} // namespace AngelScriptEngine
|
} // namespace StudioAPI
|
||||||
|
|
||||||
void AngelScriptEngine::raiseError() {
|
void StudioAPI::raiseError() {
|
||||||
if (AngelScriptEngine::executingModule)
|
if (StudioAPI::executingModule)
|
||||||
executingModule->invalidate();
|
executingModule->invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AngelScriptEngine::initialize() {
|
void StudioAPI::initialize() {
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
// Deinitialize if its initialized
|
// Deinitialize if its initialized
|
||||||
@ -61,23 +62,23 @@ namespace Deer {
|
|||||||
module.init();
|
module.init();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void AngelScriptEngine::update() {
|
void StudioAPI::update() {
|
||||||
for (Module& module : modules) {
|
for (Module& module : modules) {
|
||||||
module.update();
|
module.update();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void AngelScriptEngine::shutdown() {
|
void StudioAPI::shutdown() {
|
||||||
for (Module& module : modules) {
|
for (Module& module : modules) {
|
||||||
module.shutdown();
|
module.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void AngelScriptEngine::render() {
|
void StudioAPI::render() {
|
||||||
for (Module& module : modules) {
|
for (Module& module : modules) {
|
||||||
module.render();
|
module.render();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AngelScriptEngine::deinitialize() {
|
void StudioAPI::deinitialize() {
|
||||||
for (Module& module : modules) {
|
for (Module& module : modules) {
|
||||||
module.shutdown();
|
module.shutdown();
|
||||||
}
|
}
|
||||||
@ -95,7 +96,7 @@ namespace Deer {
|
|||||||
scriptEngine = nullptr;
|
scriptEngine = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AngelScriptEngine::registerStructs() {
|
void StudioAPI::registerStructs() {
|
||||||
registerMathStructs();
|
registerMathStructs();
|
||||||
registerResourceStructs();
|
registerResourceStructs();
|
||||||
registerEntityEnvironmentStructs();
|
registerEntityEnvironmentStructs();
|
||||||
@ -105,7 +106,7 @@ namespace Deer {
|
|||||||
registerUIStructs();
|
registerUIStructs();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AngelScriptEngine::registerFunctions() {
|
void StudioAPI::registerFunctions() {
|
||||||
registerUIFunctions();
|
registerUIFunctions();
|
||||||
registerMathFunctions();
|
registerMathFunctions();
|
||||||
registerResourceFunctions();
|
registerResourceFunctions();
|
||||||
|
|||||||
@ -3,7 +3,7 @@
|
|||||||
#include "angelscript.h"
|
#include "angelscript.h"
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace AngelScriptEngine {
|
namespace StudioAPI {
|
||||||
const char* getAngelScriptReturnCodeString(int code) {
|
const char* getAngelScriptReturnCodeString(int code) {
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case asSUCCESS:
|
case asSUCCESS:
|
||||||
@ -61,5 +61,5 @@ namespace Deer {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace AngelScriptEngine
|
} // namespace StudioAPI
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
@ -3,31 +3,31 @@
|
|||||||
#include "angelscript.h"
|
#include "angelscript.h"
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace AngelScriptEngine {
|
namespace StudioAPI {
|
||||||
const char* getAngelScriptReturnCodeString(int code);
|
const char* getAngelScriptReturnCodeString(int code);
|
||||||
bool ImplementsInterface(asITypeInfo* type, asITypeInfo* iface);
|
bool ImplementsInterface(asITypeInfo* type, asITypeInfo* iface);
|
||||||
}
|
} // namespace StudioAPI
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
|
|
||||||
#define AS_CHECK(f) \
|
#define AS_CHECK(f) \
|
||||||
{ \
|
{ \
|
||||||
int __r = f; \
|
int __r = f; \
|
||||||
if (__r < 0) { \
|
if (__r < 0) { \
|
||||||
DEER_EDITOR_ENGINE_ERROR("Error at line: {0}:{1} -> {2}", __FILE__, __LINE__, Deer::AngelScriptEngine::getAngelScriptReturnCodeString(__r)); \
|
DEER_EDITOR_ENGINE_ERROR("Error at line: {0}:{1} -> {2}", __FILE__, __LINE__, Deer::StudioAPI::getAngelScriptReturnCodeString(__r)); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#define AS_CHECK_ADDITIONAL_INFO(f, i) \
|
#define AS_CHECK_ADDITIONAL_INFO(f, i) \
|
||||||
{ \
|
{ \
|
||||||
int __r = f; \
|
int __r = f; \
|
||||||
if (__r < 0) { \
|
if (__r < 0) { \
|
||||||
DEER_EDITOR_ENGINE_ERROR("Error at line: {0}:{1} -> {2} \n {3}", __FILE__, __LINE__, Deer::AngelScriptEngine::getAngelScriptReturnCodeString(__r), i); \
|
DEER_EDITOR_ENGINE_ERROR("Error at line: {0}:{1} -> {2} \n {3}", __FILE__, __LINE__, Deer::StudioAPI::getAngelScriptReturnCodeString(__r), i); \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
#define AS_RET_CHECK(f) \
|
#define AS_RET_CHECK(f) \
|
||||||
{ \
|
{ \
|
||||||
int __r = f; \
|
int __r = f; \
|
||||||
if (__r < 0) { \
|
if (__r < 0) { \
|
||||||
DEER_EDITOR_ENGINE_ERROR("Error at line: {0}:{1} -> {2}", __FILE__, __LINE__, Deer::AngelScriptEngine::getAngelScriptReturnCodeString(__r)); \
|
DEER_EDITOR_ENGINE_ERROR("Error at line: {0}:{1} -> {2}", __FILE__, __LINE__, Deer::StudioAPI::getAngelScriptReturnCodeString(__r)); \
|
||||||
return; \
|
return; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
#include "angelscript.h"
|
#include "angelscript.h"
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace AngelScriptEngine {
|
namespace StudioAPI {
|
||||||
Module::Module(const ModuleDescription& _mi) : moduleInfo(_mi) {}
|
Module::Module(const ModuleDescription& _mi) : moduleInfo(_mi) {}
|
||||||
|
|
||||||
void Module::extract(asIScriptModule* _module) {
|
void Module::extract(asIScriptModule* _module) {
|
||||||
@ -33,7 +33,7 @@ namespace Deer {
|
|||||||
if (state != ModuleState::Built)
|
if (state != ModuleState::Built)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
angelscriptModule = AngelScriptEngine::scriptEngine->GetModule(moduleInfo.moduleName.c_str());
|
angelscriptModule = StudioAPI::scriptEngine->GetModule(moduleInfo.moduleName.c_str());
|
||||||
|
|
||||||
for (Service& service : services)
|
for (Service& service : services)
|
||||||
service.updateTypes(angelscriptModule);
|
service.updateTypes(angelscriptModule);
|
||||||
@ -89,5 +89,5 @@ namespace Deer {
|
|||||||
services.clear();
|
services.clear();
|
||||||
panels.clear();
|
panels.clear();
|
||||||
}
|
}
|
||||||
}; // namespace AngelScriptEngine
|
}; // namespace StudioAPI
|
||||||
}; // namespace Deer
|
}; // namespace Deer
|
||||||
@ -4,7 +4,7 @@
|
|||||||
#include <cereal/types/vector.hpp>
|
#include <cereal/types/vector.hpp>
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace AngelScriptEngine {
|
namespace StudioAPI {
|
||||||
template <class Archive>
|
template <class Archive>
|
||||||
void serialize(Archive& archive,
|
void serialize(Archive& archive,
|
||||||
ModuleDescription& m) {
|
ModuleDescription& m) {
|
||||||
@ -13,5 +13,5 @@ namespace Deer {
|
|||||||
archive(cereal::make_nvp("requires", m.module_requires));
|
archive(cereal::make_nvp("requires", m.module_requires));
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace AngelScriptEngine
|
} // namespace StudioAPI
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
@ -20,12 +20,12 @@
|
|||||||
namespace fs = std::filesystem;
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace AngelScriptEngine {
|
namespace StudioAPI {
|
||||||
bool loadModule(Module& module);
|
bool loadModule(Module& module);
|
||||||
void loadModuleInfo(const Path& path);
|
void loadModuleInfo(const Path& path);
|
||||||
} // namespace AngelScriptEngine
|
} // namespace StudioAPI
|
||||||
|
|
||||||
asIScriptFunction* AngelScriptEngine::getFactory(asITypeInfo* type) {
|
asIScriptFunction* StudioAPI::getFactory(asITypeInfo* type) {
|
||||||
std::string callString = "";
|
std::string callString = "";
|
||||||
if (strlen(type->GetNamespace())) {
|
if (strlen(type->GetNamespace())) {
|
||||||
callString += type->GetNamespace();
|
callString += type->GetNamespace();
|
||||||
@ -43,7 +43,7 @@ namespace Deer {
|
|||||||
return type->GetFactoryByDecl(callString.c_str());
|
return type->GetFactoryByDecl(callString.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AngelScriptEngine::loadModule(Module& module) {
|
bool StudioAPI::loadModule(Module& module) {
|
||||||
if (module.state != ModuleState::NotBuilt)
|
if (module.state != ModuleState::NotBuilt)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ namespace Deer {
|
|||||||
asIScriptModule* as_module = scriptBuilder.GetModule();
|
asIScriptModule* as_module = scriptBuilder.GetModule();
|
||||||
|
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
DEER_EDITOR_ENGINE_ERROR("Failed compiling module {}\nerror: {}", module.moduleInfo.moduleName.c_str(), Deer::AngelScriptEngine::getAngelScriptReturnCodeString(err));
|
DEER_EDITOR_ENGINE_ERROR("Failed compiling module {}\nerror: {}", module.moduleInfo.moduleName.c_str(), Deer::StudioAPI::getAngelScriptReturnCodeString(err));
|
||||||
module.state = ModuleState::CompilationFailed;
|
module.state = ModuleState::CompilationFailed;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -117,7 +117,7 @@ namespace Deer {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void AngelScriptEngine::loadModuleInfo(const Path& path) {
|
void StudioAPI::loadModuleInfo(const Path& path) {
|
||||||
ModuleDescription desc;
|
ModuleDescription desc;
|
||||||
|
|
||||||
std::ifstream is((path / "module.json").string());
|
std::ifstream is((path / "module.json").string());
|
||||||
@ -165,7 +165,7 @@ namespace Deer {
|
|||||||
modules.push_back({desc});
|
modules.push_back({desc});
|
||||||
}
|
}
|
||||||
|
|
||||||
void AngelScriptEngine::loadModules() {
|
void StudioAPI::loadModules() {
|
||||||
const Path path = Path("Editor") / Path("Modules");
|
const Path path = Path("Editor") / Path("Modules");
|
||||||
|
|
||||||
if (!fs::exists(path) || !fs::is_directory(path)) {
|
if (!fs::exists(path) || !fs::is_directory(path)) {
|
||||||
|
|||||||
@ -14,7 +14,6 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <string_view>
|
#include <string_view>
|
||||||
|
|
||||||
#include "DeerRender/DataStore.h"
|
|
||||||
#include "DeerRender/Tools/Path.h"
|
#include "DeerRender/Tools/Path.h"
|
||||||
|
|
||||||
static std::stringstream stream;
|
static std::stringstream stream;
|
||||||
@ -268,7 +267,7 @@ void printGlobalTypedef(const asIScriptEngine& engine) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace AngelScriptEngine {
|
namespace StudioAPI {
|
||||||
void Module::generatePredefined() {
|
void Module::generatePredefined() {
|
||||||
stream.clear();
|
stream.clear();
|
||||||
stream.str("");
|
stream.str("");
|
||||||
@ -288,5 +287,5 @@ namespace Deer {
|
|||||||
predefinedFile.write(info.c_str(), info.size());
|
predefinedFile.write(info.c_str(), info.size());
|
||||||
predefinedFile.close();
|
predefinedFile.close();
|
||||||
}
|
}
|
||||||
} // namespace AngelScriptEngine
|
} // namespace StudioAPI
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
@ -4,7 +4,7 @@
|
|||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace AngelScriptEngine {
|
namespace StudioAPI {
|
||||||
Panel::Panel(asITypeInfo* _info)
|
Panel::Panel(asITypeInfo* _info)
|
||||||
: Service(_info) {
|
: Service(_info) {
|
||||||
|
|
||||||
@ -54,5 +54,5 @@ namespace Deer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Panel::~Panel() {}
|
Panel::~Panel() {}
|
||||||
} // namespace AngelScriptEngine
|
} // namespace StudioAPI
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
@ -1,35 +0,0 @@
|
|||||||
#include "DeerStudio/StudioAPI/Engine.h"
|
|
||||||
#include "DeerStudio/AngelScriptEngine/AngelScriptRegisters.h"
|
|
||||||
#include "DeerStudio/StudioAPI/Debug.h"
|
|
||||||
|
|
||||||
namespace Deer {
|
|
||||||
void AngelScriptEngine::registerEngineFunctions() {
|
|
||||||
scriptEngine->SetDefaultNamespace("Engine");
|
|
||||||
REGISTER_GLOBAL_FUNC("void print(const string&in text)", StudioAPI::print);
|
|
||||||
scriptEngine->SetDefaultNamespace("");
|
|
||||||
|
|
||||||
scriptEngine->SetDefaultNamespace("Path");
|
|
||||||
REGISTER_GLOBAL_FUNC("string getParent(const string&in path)", StudioAPI::getParentPath);
|
|
||||||
REGISTER_GLOBAL_FUNC("string getParentName(const string&in path)", StudioAPI::getParentPathName);
|
|
||||||
REGISTER_GLOBAL_FUNC("string getName(const string&in path)", StudioAPI::getPathName);
|
|
||||||
REGISTER_GLOBAL_FUNC("array<string>@ divide(const string&in path)", StudioAPI::dividePath_angelscript);
|
|
||||||
scriptEngine->SetDefaultNamespace("");
|
|
||||||
}
|
|
||||||
|
|
||||||
void AngelScriptEngine::registerEngineStructs() {
|
|
||||||
AS_RET_CHECK(scriptEngine->RegisterInterface("Panel"));
|
|
||||||
AS_RET_CHECK(scriptEngine->RegisterInterfaceMethod("Panel", "void render()"));
|
|
||||||
|
|
||||||
AS_RET_CHECK(scriptEngine->RegisterInterface("Service"));
|
|
||||||
|
|
||||||
AS_CHECK(scriptEngine->RegisterFuncdef("void SimpleFunction()"));
|
|
||||||
AS_CHECK(scriptEngine->RegisterFuncdef("void ReciverFunction(any@)"));
|
|
||||||
AS_CHECK(scriptEngine->RegisterFuncdef("void TransferFunction(any@, any@)"));
|
|
||||||
}
|
|
||||||
|
|
||||||
void AngelScriptEngine::extractBaseTypes() {
|
|
||||||
panelBaseType = scriptEngine->GetTypeInfoByDecl("Panel");
|
|
||||||
serviceBaseType = scriptEngine->GetTypeInfoByDecl("Service");
|
|
||||||
arrayStringBaseType = scriptEngine->GetTypeInfoByDecl("array<string>");
|
|
||||||
}
|
|
||||||
} // namespace Deer
|
|
||||||
@ -1,102 +0,0 @@
|
|||||||
#include "DeerStudio/StudioAPI/Entity.h"
|
|
||||||
#include "DeerStudio/AngelScriptEngine/AngelScriptRegisters.h"
|
|
||||||
|
|
||||||
namespace Deer {
|
|
||||||
namespace AngelScriptEngine {
|
|
||||||
void registerTransformComponentFunctions();
|
|
||||||
void registerMeshComponentFunction();
|
|
||||||
void registerShaderComponentFunctions();
|
|
||||||
void registerComponentComponentFunctions();
|
|
||||||
} // namespace AngelScriptEngine
|
|
||||||
|
|
||||||
void AngelScriptEngine::registerEntityStructs() {
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectType("Entity", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectType("EntityChilds", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectType("TransformComponent", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectType("MeshComponent", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectType("ShaderComponent", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectType("CameraComponent", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
|
|
||||||
}
|
|
||||||
|
|
||||||
void AngelScriptEngine::registerEntityFunctions() {
|
|
||||||
registerTransformComponentFunctions();
|
|
||||||
registerMeshComponentFunction();
|
|
||||||
registerShaderComponentFunctions();
|
|
||||||
registerComponentComponentFunctions();
|
|
||||||
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "string get_name() const property", StudioAPI::EntityStruct, getName);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "void set_name(string& in) property", StudioAPI::EntityStruct, setName);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "int get_id() const property", StudioAPI::EntityStruct, getId);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "Entity createChild(const string& in)", StudioAPI::EntityStruct, createChild);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "bool get_isRoot() const property", StudioAPI::EntityStruct, isRoot);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "void destroy()", StudioAPI::EntityStruct, destroy);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "bool get_exists() const property", StudioAPI::EntityStruct, exists);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "Entity get_parent() property", StudioAPI::EntityStruct, getParent);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "void set_parent(Entity) property", StudioAPI::EntityStruct, setParent);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "bool isDescendantOf(Entity)", StudioAPI::EntityStruct, isDescendantOf);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "bool opEquals(const Entity &in) const", StudioAPI::EntityStruct, opEquals);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "EntityChilds get_childs() const property", StudioAPI::EntityStruct, getSelf);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "TransformComponent get_transform() const property", StudioAPI::EntityStruct, getSelf);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "MeshComponent getMeshComponent()", StudioAPI::EntityStruct, getMeshComponent);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "MeshComponent createMeshComponent()", StudioAPI::EntityStruct, createMeshComponent);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "bool hasMeshComponent()", StudioAPI::EntityStruct, hasMeshComponent);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "void removeMeshComponent()", StudioAPI::EntityStruct, removeMeshComponent);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "ShaderComponent getShaderComponent()", StudioAPI::EntityStruct, getShaderComponent);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "ShaderComponent createShaderComponent()", StudioAPI::EntityStruct, createShaderComponent);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "bool hasShaderComponent()", StudioAPI::EntityStruct, hasShaderComponent);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "void removeShaderComponent()", StudioAPI::EntityStruct, removeShaderComponent);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "CameraComponent getCameraComponent()", StudioAPI::EntityStruct, getCameraComponent);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "CameraComponent createCameraComponent()", StudioAPI::EntityStruct, createCameraComponent);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "bool hasCameraComponent()", StudioAPI::EntityStruct, hasCameraComponent);
|
|
||||||
REGISTER_OBJECT_METHOD("Entity", "void removeCameraComponent()", StudioAPI::EntityStruct, removeCameraComponent);
|
|
||||||
|
|
||||||
scriptEngine->SetDefaultNamespace("Engine");
|
|
||||||
REGISTER_GLOBAL_FUNC("Entity getRoot()", StudioAPI::getRoot);
|
|
||||||
scriptEngine->SetDefaultNamespace("");
|
|
||||||
|
|
||||||
REGISTER_OBJECT_METHOD("EntityChilds", "int get_count() const property", StudioAPI::EntityChildArrayStruct, getChildCount);
|
|
||||||
REGISTER_OBJECT_METHOD("EntityChilds", "Entity opIndex(int) const", StudioAPI::EntityChildArrayStruct, getChild);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AngelScriptEngine::registerMeshComponentFunction() {
|
|
||||||
REGISTER_OBJECT_METHOD("MeshComponent", "bool get_isActive() const property", StudioAPI::MeshComponentStruct, isActive);
|
|
||||||
REGISTER_OBJECT_METHOD("MeshComponent", "bool get_hasMesh() const property", StudioAPI::MeshComponentStruct, hasMesh);
|
|
||||||
REGISTER_OBJECT_METHOD("MeshComponent", "void clear()", StudioAPI::MeshComponentStruct, clear);
|
|
||||||
REGISTER_OBJECT_METHOD("MeshComponent", "GPUMesh get_meshResource() property", StudioAPI::MeshComponentStruct, getMesh);
|
|
||||||
REGISTER_OBJECT_METHOD("MeshComponent", "void set_meshResource(GPUMesh) property", StudioAPI::MeshComponentStruct, setMesh);
|
|
||||||
REGISTER_OBJECT_METHOD("MeshComponent", "void set_isActive(const bool) const property", StudioAPI::MeshComponentStruct, setActive);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AngelScriptEngine::registerTransformComponentFunctions() {
|
|
||||||
REGISTER_OBJECT_METHOD("TransformComponent", "vec3 get_position() const property", StudioAPI::TransformComponentStruct, getPosition);
|
|
||||||
REGISTER_OBJECT_METHOD("TransformComponent", "vec3 get_scale() const property", StudioAPI::TransformComponentStruct, getScale);
|
|
||||||
REGISTER_OBJECT_METHOD("TransformComponent", "vec3 get_rotation() const property", StudioAPI::TransformComponentStruct, getRotation);
|
|
||||||
|
|
||||||
REGISTER_OBJECT_METHOD("TransformComponent", "void set_position(const vec3) property", StudioAPI::TransformComponentStruct, setPosition);
|
|
||||||
REGISTER_OBJECT_METHOD("TransformComponent", "void set_scale(const vec3) property", StudioAPI::TransformComponentStruct, setScale);
|
|
||||||
REGISTER_OBJECT_METHOD("TransformComponent", "void set_rotation(const vec3) property", StudioAPI::TransformComponentStruct, setRotation);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AngelScriptEngine::registerShaderComponentFunctions() {
|
|
||||||
REGISTER_OBJECT_METHOD("ShaderComponent", "bool get_hasShader() const property", StudioAPI::ShaderComponentStruct, hasShader);
|
|
||||||
REGISTER_OBJECT_METHOD("ShaderComponent", "void clear()", StudioAPI::ShaderComponentStruct, clear);
|
|
||||||
|
|
||||||
REGISTER_OBJECT_METHOD("ShaderComponent", "Shader get_shader() const property", StudioAPI::ShaderComponentStruct, getShader);
|
|
||||||
REGISTER_OBJECT_METHOD("ShaderComponent", "void set_shader(Shader) property", StudioAPI::ShaderComponentStruct, setShader);
|
|
||||||
|
|
||||||
REGISTER_OBJECT_METHOD("ShaderComponent", "Texture get_texture() const property", StudioAPI::ShaderComponentStruct, getTexture);
|
|
||||||
REGISTER_OBJECT_METHOD("ShaderComponent", "void set_texture(Texture) property", StudioAPI::ShaderComponentStruct, setTexture);
|
|
||||||
}
|
|
||||||
|
|
||||||
void AngelScriptEngine::registerComponentComponentFunctions() {
|
|
||||||
REGISTER_OBJECT_METHOD("CameraComponent", "float get_fov() const property", StudioAPI::CameraComponentStruct, getFov);
|
|
||||||
REGISTER_OBJECT_METHOD("CameraComponent", "float get_aspectRatio() const property", StudioAPI::CameraComponentStruct, getAspectRation);
|
|
||||||
REGISTER_OBJECT_METHOD("CameraComponent", "float get_nearZ() const property", StudioAPI::CameraComponentStruct, getNearZ);
|
|
||||||
REGISTER_OBJECT_METHOD("CameraComponent", "float get_farZ() const property", StudioAPI::CameraComponentStruct, getFarZ);
|
|
||||||
|
|
||||||
REGISTER_OBJECT_METHOD("CameraComponent", "void set_fov(float) property", StudioAPI::CameraComponentStruct, setFov);
|
|
||||||
REGISTER_OBJECT_METHOD("CameraComponent", "void set_aspectRatio(float) property", StudioAPI::CameraComponentStruct, setAspectRation);
|
|
||||||
REGISTER_OBJECT_METHOD("CameraComponent", "void set_nearZ(float) property", StudioAPI::CameraComponentStruct, setNearZ);
|
|
||||||
REGISTER_OBJECT_METHOD("CameraComponent", "void set_farZ(float) property", StudioAPI::CameraComponentStruct, setFarZ);
|
|
||||||
}
|
|
||||||
} // namespace Deer
|
|
||||||
@ -1,56 +0,0 @@
|
|||||||
#include "DeerStudio/StudioAPI/Math.h"
|
|
||||||
#include "DeerStudio/AngelScriptEngine/AngelScriptRegisters.h"
|
|
||||||
|
|
||||||
namespace Deer {
|
|
||||||
void AngelScriptEngine::registerMathStructs() {
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectType("vec3", sizeof(glm::vec3), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<glm::vec3>() | asOBJ_APP_CLASS_ALLFLOATS));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectBehaviour("vec3", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(StudioAPI::vec3_constructor), asCALL_CDECL_OBJLAST));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectBehaviour("vec3", asBEHAVE_CONSTRUCT, "void f(float, float = 0, float = 0)", asFUNCTION(StudioAPI::vec3_constructor_params), asCALL_CDECL_OBJLAST));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectProperty("vec3", "float x", asOFFSET(glm::vec3, x)));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectProperty("vec3", "float y", asOFFSET(glm::vec3, y)));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectProperty("vec3", "float z", asOFFSET(glm::vec3, z)));
|
|
||||||
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectType("quat", sizeof(glm::quat), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<glm::quat>() | asOBJ_APP_CLASS_ALLFLOATS));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectProperty("quat", "float x", asOFFSET(glm::quat, x)));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectProperty("quat", "float y", asOFFSET(glm::quat, y)));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectProperty("quat", "float z", asOFFSET(glm::quat, z)));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectProperty("quat", "float w", asOFFSET(glm::quat, w)));
|
|
||||||
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectType("Transform", sizeof(TransformComponent), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<TransformComponent>()));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectProperty("Transform", "vec3 position", asOFFSET(TransformComponent, position)));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectProperty("Transform", "vec3 scale", asOFFSET(TransformComponent, scale)));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectProperty("Transform", "quat rotation", asOFFSET(TransformComponent, rotation)));
|
|
||||||
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectType("Camera", sizeof(CameraComponent), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<CameraComponent>()));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectProperty("Camera", "float fov", asOFFSET(CameraComponent, fov)));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectProperty("Camera", "float aspect", asOFFSET(CameraComponent, aspect)));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectProperty("Camera", "float nearZ", asOFFSET(CameraComponent, nearZ)));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectProperty("Camera", "float farZ", asOFFSET(CameraComponent, farZ)));
|
|
||||||
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectType("WorldCamera", sizeof(WorldCamera), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<WorldCamera>()));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectProperty("WorldCamera", "Camera camera", asOFFSET(WorldCamera, camera)));
|
|
||||||
AS_CHECK(scriptEngine->RegisterObjectProperty("WorldCamera", "Transform transform", asOFFSET(WorldCamera, transform)));
|
|
||||||
}
|
|
||||||
|
|
||||||
void AngelScriptEngine::registerMathFunctions() {
|
|
||||||
REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opAdd(const vec3 &in)", StudioAPI::vec3_add);
|
|
||||||
REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opSub(const vec3 &in) const", StudioAPI::vec3_sub);
|
|
||||||
REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opNeg() const", StudioAPI::vec3_neg);
|
|
||||||
REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opMul(float) const", StudioAPI::vec3_mult);
|
|
||||||
REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opMul_r(float) const", StudioAPI::vec3_mult);
|
|
||||||
|
|
||||||
REGISTER_EXT_OBJECT_CONSTRUCTOR("quat", "void f()", StudioAPI::quat_construct);
|
|
||||||
REGISTER_EXT_OBJECT_CONSTRUCTOR("quat", "void f(float, float, float, float)", StudioAPI::quat_constructFromValue);
|
|
||||||
REGISTER_EXT_OBJECT_DESTRUCTOR("quat", "void f()", StudioAPI::quat_destruct);
|
|
||||||
|
|
||||||
REGISTER_EXT_OBJECT_METHOD("quat", "quat opMul(const quat &in) const", StudioAPI::quat_multiply);
|
|
||||||
REGISTER_EXT_OBJECT_METHOD("quat", "vec3 getEuler() const", StudioAPI::quat_getEuler);
|
|
||||||
REGISTER_EXT_OBJECT_METHOD("quat", "void setEuler(vec3)", StudioAPI::quat_setEuler);
|
|
||||||
|
|
||||||
REGISTER_EXT_OBJECT_CONSTRUCTOR("Transform", "void f()", StudioAPI::transform_construct);
|
|
||||||
REGISTER_EXT_OBJECT_CONSTRUCTOR("Camera", "void f()", StudioAPI::camera_construct);
|
|
||||||
REGISTER_EXT_OBJECT_CONSTRUCTOR("WorldCamera", "void f()", StudioAPI::sceneCamera_Construct);
|
|
||||||
|
|
||||||
REGISTER_EXT_OBJECT_METHOD("Transform", "vec3 relative(vec3)", StudioAPI::transform_relative);
|
|
||||||
}
|
|
||||||
} // namespace Deer
|
|
||||||
@ -8,7 +8,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace AngelScriptEngine {
|
namespace StudioAPI {
|
||||||
void Service::init() {
|
void Service::init() {
|
||||||
asIScriptFunction* constructorFunction = getFactory(type);
|
asIScriptFunction* constructorFunction = getFactory(type);
|
||||||
|
|
||||||
@ -294,5 +294,5 @@ namespace Deer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Service::~Service() {}
|
Service::~Service() {}
|
||||||
} // namespace AngelScriptEngine
|
} // namespace StudioAPI
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
@ -1,60 +1,62 @@
|
|||||||
#include "DeerStudio/DeerStudio.h"
|
#include "DeerStudio/DeerStudio.h"
|
||||||
#include "DeerStudio/AngelScriptEngine.h"
|
// #include "DeerStudio/AngelScriptEngine.h"
|
||||||
|
|
||||||
#include "DeerRender/DataStore.h"
|
#include "DeerRender/Engine.h"
|
||||||
#include "DeerRender/Tools/Path.h"
|
#include "DeerRender/Universe.h"
|
||||||
#include "DeerRender/World.h"
|
#include "DeerRender/World.h"
|
||||||
|
|
||||||
#include "DeerRender/Application.h"
|
|
||||||
|
|
||||||
// TMP
|
// TMP
|
||||||
#include "DeerRender/Mesh.h"
|
|
||||||
#include "DeerRender/Resource.h"
|
|
||||||
#include "DeerStudio/Fonts.h"
|
#include "DeerStudio/Fonts.h"
|
||||||
#include "DeerStudio/Style.h"
|
#include "DeerStudio/Style.h"
|
||||||
// TMP
|
// TMP
|
||||||
|
|
||||||
#include "DeerStudio/StudioAPI/UI.h"
|
#include "DeerStudio/StudioAPI.h"
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
|
class FrameBuffer;
|
||||||
|
|
||||||
namespace DeerStudio {
|
namespace DeerStudio {
|
||||||
|
Universe::WorldHandle mainWorld;
|
||||||
|
|
||||||
|
void onUpdate();
|
||||||
|
void onRender();
|
||||||
|
void onEvent(Event& e);
|
||||||
|
bool onWindowCloseEvent(WindowCloseEvent&);
|
||||||
|
|
||||||
|
void worldRender(World& world);
|
||||||
|
void worldUpdate(World& world);
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
Log::init();
|
Engine::init();
|
||||||
Application::initWindow();
|
Engine::setEventCallback(DeerStudio::onEvent);
|
||||||
|
|
||||||
// DataStore::loadVoxelsData();
|
StudioAPI::registerStudioAPI();
|
||||||
// DataStore::loadVoxelsAspect();
|
|
||||||
// DataStore::generateTextureAtlas();
|
|
||||||
// DataStore::loadVoxelsShaders();
|
|
||||||
|
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 20));
|
||||||
initializeFonts();
|
initializeFonts();
|
||||||
SetupImGuiStyle();
|
SetupImGuiStyle();
|
||||||
|
|
||||||
AngelScriptEngine::initialize();
|
WorldSettings worldSettings = {
|
||||||
RenderUtils::initializeRenderUtils();
|
.updateCallback = worldUpdate,
|
||||||
|
.updateFrequency = 60,
|
||||||
|
.renderCallback = worldRender,
|
||||||
|
.renderFrequency = 144,
|
||||||
|
};
|
||||||
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(20, 20));
|
mainWorld = Universe::createWorld(worldSettings);
|
||||||
|
Universe::getWorld(mainWorld).execute();
|
||||||
|
|
||||||
Application::setTickCallback(DeerStudio::onUpdate);
|
StudioAPI::deinitialize();
|
||||||
Application::setRenderCallback(DeerStudio::onRender);
|
Engine::shutdown();
|
||||||
Application::setEventCallback(DeerStudio::onEvent);
|
} // namespace DeerStudio
|
||||||
|
|
||||||
Application::run();
|
void worldUpdate(World& world) {
|
||||||
|
StudioAPI::update();
|
||||||
AngelScriptEngine::deinitialize();
|
|
||||||
RenderUtils::deinitializeRenderUtils();
|
|
||||||
|
|
||||||
World::clear();
|
|
||||||
|
|
||||||
Application::shutdownWindow();
|
|
||||||
Log::shutdown();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onUpdate() {
|
void worldRender(World& world) {
|
||||||
AngelScriptEngine::update();
|
Engine::beginRender();
|
||||||
}
|
|
||||||
|
|
||||||
void onRender() {
|
|
||||||
static bool opt_fullscreen = true;
|
static bool opt_fullscreen = true;
|
||||||
static bool opt_padding = false;
|
static bool opt_padding = false;
|
||||||
static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None;
|
static ImGuiDockNodeFlags dockspace_flags = ImGuiDockNodeFlags_None;
|
||||||
@ -102,8 +104,10 @@ namespace Deer {
|
|||||||
// TerrainEditor::onImGui();
|
// TerrainEditor::onImGui();
|
||||||
// viewport_onImGui();
|
// viewport_onImGui();
|
||||||
|
|
||||||
AngelScriptEngine::render();
|
StudioAPI::render();
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
|
Engine::endRender();
|
||||||
}
|
}
|
||||||
|
|
||||||
void onEvent(Event& e) {
|
void onEvent(Event& e) {
|
||||||
@ -113,7 +117,7 @@ namespace Deer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool onWindowCloseEvent(WindowCloseEvent&) {
|
bool onWindowCloseEvent(WindowCloseEvent&) {
|
||||||
Application::shutdown();
|
Universe::getWorld(mainWorld).stopExecution();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} // namespace DeerStudio
|
} // namespace DeerStudio
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
#include "Fonts.h"
|
#include "Fonts.h"
|
||||||
#include "DeerRender/DataStore.h"
|
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
ImFont* normalText;
|
ImFont* normalText;
|
||||||
@ -20,7 +19,7 @@ namespace Deer {
|
|||||||
config.MergeMode = true;
|
config.MergeMode = true;
|
||||||
config.PixelSnapH = true;
|
config.PixelSnapH = true;
|
||||||
|
|
||||||
ImWchar icons_ranges[] = { 0xf000, 0xf3ff, 0 };
|
ImWchar icons_ranges[] = {0xf000, 0xf3ff, 0};
|
||||||
// Merge into normalText (18 px)
|
// Merge into normalText (18 px)
|
||||||
{
|
{
|
||||||
ImFontConfig cfg;
|
ImFontConfig cfg;
|
||||||
@ -42,7 +41,6 @@ namespace Deer {
|
|||||||
io.Fonts->AddFontFromFileTTF(faNPath.generic_string().c_str(), 20, &cfg);
|
io.Fonts->AddFontFromFileTTF(faNPath.generic_string().c_str(), 20, &cfg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
io.Fonts->AddFontFromFileTTF(faPath.generic_string().c_str(), 18);
|
io.Fonts->AddFontFromFileTTF(faPath.generic_string().c_str(), 18);
|
||||||
|
|
||||||
io.Fonts->Build();
|
io.Fonts->Build();
|
||||||
|
|||||||
38
DeerStudio/src/DeerStudio/Registers/Engine.cpp
Normal file
38
DeerStudio/src/DeerStudio/Registers/Engine.cpp
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
#include "DeerStudio/StudioAPI/Engine.h"
|
||||||
|
#include "DeerStudio/Registers/Registers.h"
|
||||||
|
#include "DeerStudio/StudioAPI.h"
|
||||||
|
#include "DeerStudio/StudioAPI/Debug.h"
|
||||||
|
#include "DeerStudio/StudioAPI/Resources.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
void StudioAPI::registerEngineFunctions() {
|
||||||
|
asIScriptEngine* scriptEngine = engineRegistry->bind();
|
||||||
|
|
||||||
|
REGISTER_GLOBAL_FUNC(engine, "void print(const string&in text)", StudioAPI::print);
|
||||||
|
REGISTER_GLOBAL_FUNC(engine, "string getParent(const string&in path)", StudioAPI::getParentPath);
|
||||||
|
REGISTER_GLOBAL_FUNC(engine, "string getParentName(const string&in path)", StudioAPI::getParentPathName);
|
||||||
|
REGISTER_GLOBAL_FUNC(engine, "string getName(const string&in path)", StudioAPI::getPathName);
|
||||||
|
REGISTER_GLOBAL_FUNC(engine, "array<string>@ divide(const string&in path)", StudioAPI::dividePath_angelscript);
|
||||||
|
engineRegistry->unbind()
|
||||||
|
}
|
||||||
|
|
||||||
|
void StudioAPI::registerEngineStructs() {
|
||||||
|
asIScriptEngine* scriptEngine = engineRegistry->bindNoNamespace();
|
||||||
|
AS_RET_CHECK(scriptEngine->RegisterInterface("Panel"));
|
||||||
|
AS_RET_CHECK(scriptEngine->RegisterInterfaceMethod("Panel", "void render()"));
|
||||||
|
AS_RET_CHECK(scriptEngine->RegisterInterface("Service"));
|
||||||
|
|
||||||
|
AS_CHECK(scriptEngine->RegisterFuncdef("void SimpleFunction()"));
|
||||||
|
AS_CHECK(scriptEngine->RegisterFuncdef("void ReciverFunction(any@)"));
|
||||||
|
AS_CHECK(scriptEngine->RegisterFuncdef("void TransferFunction(any@, any@)"));
|
||||||
|
engineRegistry->unbind();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StudioAPI::extractBaseTypes() {
|
||||||
|
asIScriptEngine* scriptEngine = engineRegistry->bindNoNamespace();
|
||||||
|
panelBaseType = scriptEngine->GetTypeInfoByDecl("Panel");
|
||||||
|
serviceBaseType = scriptEngine->GetTypeInfoByDecl("Service");
|
||||||
|
arrayStringBaseType = scriptEngine->GetTypeInfoByDecl("array<string>");
|
||||||
|
engineRegistry->unbind();
|
||||||
|
}
|
||||||
|
} // namespace Deer
|
||||||
111
DeerStudio/src/DeerStudio/Registers/Entity.cpp
Normal file
111
DeerStudio/src/DeerStudio/Registers/Entity.cpp
Normal file
@ -0,0 +1,111 @@
|
|||||||
|
#include "DeerStudio/StudioAPI/Entity.h"
|
||||||
|
#include "DeerStudio/Registers/Registers.h"
|
||||||
|
#include "DeerStudio/StudioAPI.h"
|
||||||
|
#include "DeerStudio/StudioAPI/Resources.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace StudioAPI {
|
||||||
|
void registerTransformComponentFunctions();
|
||||||
|
void registerMeshComponentFunction();
|
||||||
|
void registerShaderComponentFunctions();
|
||||||
|
void registerComponentComponentFunctions();
|
||||||
|
} // namespace StudioAPI
|
||||||
|
|
||||||
|
void StudioAPI::registerEntityStructs() {
|
||||||
|
asIScriptEngine* scriptEngine = entityRegistry->bindNoNamespace();
|
||||||
|
AS_CHECK(scriptEngine->RegisterObjectType("Entity", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
|
||||||
|
AS_CHECK(scriptEngine->RegisterObjectType("EntityChilds", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
|
||||||
|
AS_CHECK(scriptEngine->RegisterObjectType("TransformComponent", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
|
||||||
|
AS_CHECK(scriptEngine->RegisterObjectType("MeshComponent", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
|
||||||
|
AS_CHECK(scriptEngine->RegisterObjectType("ShaderComponent", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
|
||||||
|
AS_CHECK(scriptEngine->RegisterObjectType("CameraComponent", sizeof(StudioAPI::EntityHandleStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityHandleStruct>() | asOBJ_APP_CLASS_ALLINTS));
|
||||||
|
entityRegistry->unbind();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StudioAPI::registerEntityFunctions() {
|
||||||
|
registerTransformComponentFunctions();
|
||||||
|
registerMeshComponentFunction();
|
||||||
|
registerShaderComponentFunctions();
|
||||||
|
registerComponentComponentFunctions();
|
||||||
|
|
||||||
|
asIScriptEngine* scriptEngine = entityRegistry->bindNoNamespace();
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "string get_name() const property", StudioAPI::EntityStruct, getName);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "void set_name(string& in) property", StudioAPI::EntityStruct, setName);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "int get_id() const property", StudioAPI::EntityStruct, getId);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "Entity createChild(const string& in)", StudioAPI::EntityStruct, createChild);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "bool get_isRoot() const property", StudioAPI::EntityStruct, isRoot);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "void destroy()", StudioAPI::EntityStruct, destroy);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "bool get_exists() const property", StudioAPI::EntityStruct, exists);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "Entity get_parent() property", StudioAPI::EntityStruct, getParent);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "void set_parent(Entity) property", StudioAPI::EntityStruct, setParent);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "bool isDescendantOf(Entity)", StudioAPI::EntityStruct, isDescendantOf);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "bool opEquals(const Entity &in) const", StudioAPI::EntityStruct, opEquals);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "EntityChilds get_childs() const property", StudioAPI::EntityStruct, getSelf);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "TransformComponent get_transform() const property", StudioAPI::EntityStruct, getSelf);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "MeshComponent getMeshComponent()", StudioAPI::EntityStruct, getMeshComponent);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "MeshComponent createMeshComponent()", StudioAPI::EntityStruct, createMeshComponent);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "bool hasMeshComponent()", StudioAPI::EntityStruct, hasMeshComponent);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "void removeMeshComponent()", StudioAPI::EntityStruct, removeMeshComponent);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "ShaderComponent getShaderComponent()", StudioAPI::EntityStruct, getShaderComponent);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "ShaderComponent createShaderComponent()", StudioAPI::EntityStruct, createShaderComponent);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "bool hasShaderComponent()", StudioAPI::EntityStruct, hasShaderComponent);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "void removeShaderComponent()", StudioAPI::EntityStruct, removeShaderComponent);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "CameraComponent getCameraComponent()", StudioAPI::EntityStruct, getCameraComponent);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "CameraComponent createCameraComponent()", StudioAPI::EntityStruct, createCameraComponent);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "bool hasCameraComponent()", StudioAPI::EntityStruct, hasCameraComponent);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "Entity", "void removeCameraComponent()", StudioAPI::EntityStruct, removeCameraComponent);
|
||||||
|
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "EntityChilds", "int get_count() const property", StudioAPI::EntityChildArrayStruct, getChildCount);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "EntityChilds", "Entity opIndex(int) const", StudioAPI::EntityChildArrayStruct, getChild);
|
||||||
|
|
||||||
|
scriptEngine = entityRegistry->bind();
|
||||||
|
REGISTER_GLOBAL_FUNC(scriptEngine, "Entity getRoot()", StudioAPI::getRoot);
|
||||||
|
entityRegistry->unbind();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StudioAPI::registerMeshComponentFunction() {
|
||||||
|
asIScriptEngine* scriptEngine = entityRegistry->bindNoNamespace();
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "MeshComponent", "bool get_isActive() const property", StudioAPI::MeshComponentStruct, isActive);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "MeshComponent", "bool get_hasMesh() const property", StudioAPI::MeshComponentStruct, hasMesh);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "MeshComponent", "void clear()", StudioAPI::MeshComponentStruct, clear);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "MeshComponent", "GPUMesh get_meshResource() property", StudioAPI::MeshComponentStruct, getMesh);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "MeshComponent", "void set_meshResource(GPUMesh) property", StudioAPI::MeshComponentStruct, setMesh);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "MeshComponent", "void set_isActive(const bool) const property", StudioAPI::MeshComponentStruct, setActive);
|
||||||
|
entityRegistry->unbind();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StudioAPI::registerTransformComponentFunctions() {
|
||||||
|
asIScriptEngine* scriptEngine = entityRegistry->bindNoNamespace();
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "TransformComponent", "vec3 get_position() const property", StudioAPI::TransformComponentStruct, getPosition);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "TransformComponent", "vec3 get_scale() const property", StudioAPI::TransformComponentStruct, getScale);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "TransformComponent", "vec3 get_rotation() const property", StudioAPI::TransformComponentStruct, getRotation);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "TransformComponent", "void set_position(const vec3) property", StudioAPI::TransformComponentStruct, setPosition);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "TransformComponent", "void set_scale(const vec3) property", StudioAPI::TransformComponentStruct, setScale);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "TransformComponent", "void set_rotation(const vec3) property", StudioAPI::TransformComponentStruct, setRotation);
|
||||||
|
entityRegistry->unbind();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StudioAPI::registerShaderComponentFunctions() {
|
||||||
|
asIScriptEngine* scriptEngine = entityRegistry->bindNoNamespace();
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "ShaderComponent", "bool get_hasShader() const property", StudioAPI::ShaderComponentStruct, hasShader);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "ShaderComponent", "void clear()", StudioAPI::ShaderComponentStruct, clear);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "ShaderComponent", "Shader get_shader() const property", StudioAPI::ShaderComponentStruct, getShader);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "ShaderComponent", "void set_shader(Shader) property", StudioAPI::ShaderComponentStruct, setShader);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "ShaderComponent", "Texture get_texture() const property", StudioAPI::ShaderComponentStruct, getTexture);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "ShaderComponent", "void set_texture(Texture) property", StudioAPI::ShaderComponentStruct, setTexture);
|
||||||
|
entityRegistry->unbind();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StudioAPI::registerComponentComponentFunctions() {
|
||||||
|
asIScriptEngine* scriptEngine = entityRegistry->bindNoNamespace();
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "CameraComponent", "float get_fov() const property", StudioAPI::CameraComponentStruct, getFov);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "CameraComponent", "float get_aspectRatio() const property", StudioAPI::CameraComponentStruct, getAspectRation);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "CameraComponent", "float get_nearZ() const property", StudioAPI::CameraComponentStruct, getNearZ);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "CameraComponent", "float get_farZ() const property", StudioAPI::CameraComponentStruct, getFarZ);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "CameraComponent", "void set_fov(float) property", StudioAPI::CameraComponentStruct, setFov);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "CameraComponent", "void set_aspectRatio(float) property", StudioAPI::CameraComponentStruct, setAspectRation);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "CameraComponent", "void set_nearZ(float) property", StudioAPI::CameraComponentStruct, setNearZ);
|
||||||
|
REGISTER_OBJECT_METHOD(scriptEngine, "CameraComponent", "void set_farZ(float) property", StudioAPI::CameraComponentStruct, setFarZ);
|
||||||
|
entityRegistry->unbind();
|
||||||
|
}
|
||||||
|
} // namespace Deer
|
||||||
@ -1,15 +1,18 @@
|
|||||||
#include "DeerStudio/AngelScriptEngine/AngelScriptRegisters.h"
|
#include "DeerStudio/AngelScriptEngine/AngelScriptRegisters.h"
|
||||||
|
#include "DeerStudio/Registers/Registers.h"
|
||||||
|
#include "DeerStudio/StudioAPI.h"
|
||||||
#include "DeerStudio/StudioAPI/EntityEnvironment.h"
|
#include "DeerStudio/StudioAPI/EntityEnvironment.h"
|
||||||
|
#include "DeerStudio/StudioAPI/Resources.h"
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
void registerEntityEnvironmentStructs();
|
void registerEntityEnvironmentStructs();
|
||||||
void registerEntityEnvironmentFunctions();
|
void registerEntityEnvironmentFunctions();
|
||||||
|
|
||||||
void AngelScriptEngine::registerEntityEnvironmentStructs() {
|
void StudioAPI::registerEntityEnvironmentStructs() {
|
||||||
AS_CHECK(scriptEngine->RegisterObjectType("EntityEnvironment", sizeof(StudioAPI::EntityEnvironmentStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityEnvironmentStruct>() | asOBJ_APP_CLASS_ALLINTS));
|
AS_CHECK(scriptEngine->RegisterObjectType("EntityEnvironment", sizeof(StudioAPI::EntityEnvironmentStruct), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<StudioAPI::EntityEnvironmentStruct>() | asOBJ_APP_CLASS_ALLINTS));
|
||||||
}
|
}
|
||||||
|
|
||||||
void AngelScriptEngine::registerEntityEnvironmentFunctions() {
|
void StudioAPI::registerEntityEnvironmentFunctions() {
|
||||||
scriptEngine->SetDefaultNamespace("Resource");
|
scriptEngine->SetDefaultNamespace("Resource");
|
||||||
REGISTER_GLOBAL_FUNC("EntityEnvironment getMainEntityEnvironment()", StudioAPI::getMainEntityEnvironment);
|
REGISTER_GLOBAL_FUNC("EntityEnvironment getMainEntityEnvironment()", StudioAPI::getMainEntityEnvironment);
|
||||||
REGISTER_GLOBAL_FUNC("EntityEnvironment createLoadEntityEnvironment(const string&in envId)", StudioAPI::createLoadEntityEnvironment);
|
REGISTER_GLOBAL_FUNC("EntityEnvironment createLoadEntityEnvironment(const string&in envId)", StudioAPI::createLoadEntityEnvironment);
|
||||||
@ -1,5 +1,5 @@
|
|||||||
#include "DeerStudio/StudioAPI/FrameBuffer.h"
|
#include "DeerStudio/StudioAPI/FrameBuffer.h"
|
||||||
#include "DeerStudio/AngelScriptEngine/AngelScriptRegisters.h"
|
#include "DeerStudio/StudioAPI/Resources.h"
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
void AngelScriptEngine::registerFrameBufferStructs() {
|
void AngelScriptEngine::registerFrameBufferStructs() {
|
||||||
64
DeerStudio/src/DeerStudio/Registers/Math.cpp
Normal file
64
DeerStudio/src/DeerStudio/Registers/Math.cpp
Normal file
@ -0,0 +1,64 @@
|
|||||||
|
#include "DeerStudio/StudioAPI/Math.h"
|
||||||
|
#include "DeerStudio/Registers/Registers.h"
|
||||||
|
#include "DeerStudio/StudioAPI.h"
|
||||||
|
#include "DeerStudio/StudioAPI/Resources.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
void StudioAPI::registerMathStructs() {
|
||||||
|
asIScriptEngine* scriptEngine = mathRegistry->bindNoNamespace();
|
||||||
|
|
||||||
|
scriptEngine->RegisterObjectBehaviour("vec3", asBEHAVE_CONSTRUCT, "void f()", asFUNCTION(StudioAPI::vec3_constructor), asCALL_CDECL_OBJLAST);
|
||||||
|
scriptEngine->RegisterObjectBehaviour("vec3", asBEHAVE_CONSTRUCT, "void f(float, float = 0, float = 0)", asFUNCTION(StudioAPI::vec3_constructor_params), asCALL_CDECL_OBJLAST);
|
||||||
|
scriptEngine->RegisterObjectProperty("vec3", "float x", asOFFSET(glm::vec3, x));
|
||||||
|
scriptEngine->RegisterObjectProperty("vec3", "float y", asOFFSET(glm::vec3, y));
|
||||||
|
scriptEngine->RegisterObjectProperty("vec3", "float z", asOFFSET(glm::vec3, z));
|
||||||
|
|
||||||
|
scriptEngine->RegisterObjectType("quat", sizeof(glm::quat), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<glm::quat>() | asOBJ_APP_CLASS_ALLFLOATS);
|
||||||
|
scriptEngine->RegisterObjectProperty("quat", "float x", asOFFSET(glm::quat, x));
|
||||||
|
scriptEngine->RegisterObjectProperty("quat", "float y", asOFFSET(glm::quat, y));
|
||||||
|
scriptEngine->RegisterObjectProperty("quat", "float z", asOFFSET(glm::quat, z));
|
||||||
|
scriptEngine->RegisterObjectProperty("quat", "float w", asOFFSET(glm::quat, w));
|
||||||
|
|
||||||
|
scriptEngine->RegisterObjectType("Transform", sizeof(TransformComponent), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<TransformComponent>());
|
||||||
|
scriptEngine->RegisterObjectProperty("Transform", "vec3 position", asOFFSET(TransformComponent, position));
|
||||||
|
scriptEngine->RegisterObjectProperty("Transform", "vec3 scale", asOFFSET(TransformComponent, scale));
|
||||||
|
scriptEngine->RegisterObjectProperty("Transform", "quat rotation", asOFFSET(TransformComponent, rotation));
|
||||||
|
|
||||||
|
scriptEngine->RegisterObjectType("Camera", sizeof(CameraComponent), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<CameraComponent>());
|
||||||
|
scriptEngine->RegisterObjectProperty("Camera", "float fov", asOFFSET(CameraComponent, fov));
|
||||||
|
scriptEngine->RegisterObjectProperty("Camera", "float aspect", asOFFSET(CameraComponent, aspect));
|
||||||
|
scriptEngine->RegisterObjectProperty("Camera", "float nearZ", asOFFSET(CameraComponent, nearZ));
|
||||||
|
scriptEngine->RegisterObjectProperty("Camera", "float farZ", asOFFSET(CameraComponent, farZ));
|
||||||
|
|
||||||
|
scriptEngine->RegisterObjectType("WorldCamera", sizeof(WorldCamera), asOBJ_VALUE | asOBJ_POD | asGetTypeTraits<WorldCamera>());
|
||||||
|
scriptEngine->RegisterObjectProperty("WorldCamera", "Camera camera", asOFFSET(WorldCamera, camera));
|
||||||
|
scriptEngine->RegisterObjectProperty("WorldCamera", "Transform transform", asOFFSET(WorldCamera, transform));
|
||||||
|
|
||||||
|
mathRegistry->unbind();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StudioAPI::registerMathFunctions() {
|
||||||
|
asIScriptEngine* scriptEngine = mathRegistry->bindNoNamespace();
|
||||||
|
mathRegistry->bindNoNamespace();
|
||||||
|
REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opAdd(const vec3 &in)", StudioAPI::vec3_add);
|
||||||
|
REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opSub(const vec3 &in) const", StudioAPI::vec3_sub);
|
||||||
|
REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opNeg() const", StudioAPI::vec3_neg);
|
||||||
|
REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opMul(float) const", StudioAPI::vec3_mult);
|
||||||
|
REGISTER_EXT_OBJECT_METHOD("vec3", "vec3 opMul_r(float) const", StudioAPI::vec3_mult);
|
||||||
|
|
||||||
|
REGISTER_EXT_OBJECT_CONSTRUCTOR("quat", "void f()", StudioAPI::quat_construct);
|
||||||
|
REGISTER_EXT_OBJECT_CONSTRUCTOR("quat", "void f(float, float, float, float)", StudioAPI::quat_constructFromValue);
|
||||||
|
REGISTER_EXT_OBJECT_DESTRUCTOR("quat", "void f()", StudioAPI::quat_destruct);
|
||||||
|
|
||||||
|
REGISTER_EXT_OBJECT_METHOD("quat", "quat opMul(const quat &in) const", StudioAPI::quat_multiply);
|
||||||
|
REGISTER_EXT_OBJECT_METHOD("quat", "vec3 getEuler() const", StudioAPI::quat_getEuler);
|
||||||
|
REGISTER_EXT_OBJECT_METHOD("quat", "void setEuler(vec3)", StudioAPI::quat_setEuler);
|
||||||
|
|
||||||
|
REGISTER_EXT_OBJECT_CONSTRUCTOR("Transform", "void f()", StudioAPI::transform_construct);
|
||||||
|
REGISTER_EXT_OBJECT_CONSTRUCTOR("Camera", "void f()", StudioAPI::camera_construct);
|
||||||
|
REGISTER_EXT_OBJECT_CONSTRUCTOR("WorldCamera", "void f()", StudioAPI::sceneCamera_Construct);
|
||||||
|
|
||||||
|
REGISTER_EXT_OBJECT_METHOD("Transform", "vec3 relative(vec3)", StudioAPI::transform_relative);
|
||||||
|
mathRegistry->unbind();
|
||||||
|
}
|
||||||
|
} // namespace Deer
|
||||||
41
DeerStudio/src/DeerStudio/Registers/Registers.cpp
Normal file
41
DeerStudio/src/DeerStudio/Registers/Registers.cpp
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "DeerStudio/StudioAPI.h"
|
||||||
|
#include "DeerStudio/StudioAPI/Resources.h"
|
||||||
|
|
||||||
|
namespace Deer {
|
||||||
|
namespace StudioAPI {
|
||||||
|
ScriptSystem::Registry* engineRegistry = nullptr;
|
||||||
|
ScriptSystem::Registry* uiRegistry = nullptr;
|
||||||
|
ScriptSystem::Registry* entityRegistry = nullptr;
|
||||||
|
ScriptSystem::Registry* resourceRegistry = nullptr;
|
||||||
|
ScriptSystem::Registry* math = nullptr;
|
||||||
|
} // namespace StudioAPI
|
||||||
|
|
||||||
|
void StudioAPI::registerStudioAPI() {
|
||||||
|
uiRegistry = ScriptSystem::createRegistry("UI");
|
||||||
|
entityRegistry = ScriptSystem::createRegistry("Entity");
|
||||||
|
|
||||||
|
registerStructs();
|
||||||
|
registerFunctions();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StudioAPI::registerStructs() {
|
||||||
|
registerMathStructs();
|
||||||
|
registerUIStructs();
|
||||||
|
registerResourceStructs();
|
||||||
|
registerEntityEnvironmentStructs();
|
||||||
|
registerEntityStructs();
|
||||||
|
registerEngineStructs();
|
||||||
|
registerFrameBufferStructs();
|
||||||
|
}
|
||||||
|
|
||||||
|
void StudioAPI::registerFunctions() {
|
||||||
|
registerUIFunctions();
|
||||||
|
registerMathFunctions();
|
||||||
|
registerResourceFunctions();
|
||||||
|
registerEntityEnvironmentFunctions();
|
||||||
|
registerEntityFunctions();
|
||||||
|
registerEngineFunctions();
|
||||||
|
registerFrameBufferFunctions();
|
||||||
|
}
|
||||||
|
} // namespace Deer
|
||||||
@ -4,32 +4,35 @@
|
|||||||
#include "DeerStudio/AngelScriptEngine.h"
|
#include "DeerStudio/AngelScriptEngine.h"
|
||||||
#include "DeerStudio/AngelScriptEngine/ErrorHandle.h"
|
#include "DeerStudio/AngelScriptEngine/ErrorHandle.h"
|
||||||
|
|
||||||
#define REGISTER_GLOBAL_FUNC(funcdef, func) \
|
#define REGISTER_GLOBAL_FUNC(scriptEngine, funcdef, func) \
|
||||||
AS_CHECK(Deer::AngelScriptEngine::scriptEngine->RegisterGlobalFunction( \
|
AS_CHECK(scriptEngine->RegisterGlobalFunction( \
|
||||||
funcdef, \
|
funcdef, \
|
||||||
asFUNCTION(func), asCALL_CDECL))
|
asFUNCTION(func), asCALL_CDECL))
|
||||||
|
|
||||||
#define REGISTER_OBJECT_METHOD(clasdef, funcdef, clas, func) \
|
#define REGISTER_OBJECT_METHOD(scriptEngine, clasdef, funcdef, clas, func) \
|
||||||
AS_CHECK(Deer::AngelScriptEngine::scriptEngine->RegisterObjectMethod( \
|
AS_CHECK(scriptEngine->RegisterObjectMethod( \
|
||||||
clasdef, funcdef, \
|
clasdef, funcdef, \
|
||||||
asMETHOD(clas, func), asCALL_THISCALL))
|
asMETHOD(clas, func), asCALL_THISCALL))
|
||||||
|
|
||||||
#define REGISTER_EXT_OBJECT_METHOD(clasdef, funcdef, func) \
|
#define REGISTER_EXT_OBJECT_METHOD(scriptEngine, clasdef, funcdef, func) \
|
||||||
AS_CHECK(Deer::AngelScriptEngine::scriptEngine->RegisterObjectMethod( \
|
AS_CHECK(scriptEngine->RegisterObjectMethod( \
|
||||||
clasdef, funcdef, \
|
clasdef, funcdef, \
|
||||||
asFUNCTION(func), asCALL_CDECL_OBJLAST))
|
asFUNCTION(func), asCALL_CDECL_OBJLAST))
|
||||||
|
|
||||||
#define REGISTER_EXT_OBJECT_CONSTRUCTOR(clasdef, funcdef, func) \
|
#define REGISTER_EXT_OBJECT_CONSTRUCTOR(scriptEngine, clasdef, funcdef, func) \
|
||||||
AS_CHECK(Deer::AngelScriptEngine::scriptEngine->RegisterObjectBehaviour( \
|
AS_CHECK(scriptEngine->RegisterObjectBehaviour( \
|
||||||
clasdef, asBEHAVE_CONSTRUCT, funcdef, \
|
clasdef, asBEHAVE_CONSTRUCT, funcdef, \
|
||||||
asFUNCTION(func), asCALL_CDECL_OBJLAST))
|
asFUNCTION(func), asCALL_CDECL_OBJLAST))
|
||||||
#define REGISTER_EXT_OBJECT_DESTRUCTOR(clasdef, funcdef, func) \
|
#define REGISTER_EXT_OBJECT_DESTRUCTOR(scriptEngine, clasdef, funcdef, func) \
|
||||||
AS_CHECK(Deer::AngelScriptEngine::scriptEngine->RegisterObjectBehaviour( \
|
AS_CHECK(scriptEngine->RegisterObjectBehaviour( \
|
||||||
clasdef, asBEHAVE_DESTRUCT, funcdef, \
|
clasdef, asBEHAVE_DESTRUCT, funcdef, \
|
||||||
asFUNCTION(func), asCALL_CDECL_OBJLAST))
|
asFUNCTION(func), asCALL_CDECL_OBJLAST))
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace AngelScriptEngine {
|
namespace StudioAPI {
|
||||||
|
void registerStructs();
|
||||||
|
void registerFunctions();
|
||||||
|
|
||||||
void registerUIFunctions();
|
void registerUIFunctions();
|
||||||
void registerMathFunctions();
|
void registerMathFunctions();
|
||||||
void registerResourceFunctions();
|
void registerResourceFunctions();
|
||||||
@ -45,6 +48,5 @@ namespace Deer {
|
|||||||
void registerEntityStructs();
|
void registerEntityStructs();
|
||||||
void registerEngineStructs();
|
void registerEngineStructs();
|
||||||
void registerFrameBufferStructs();
|
void registerFrameBufferStructs();
|
||||||
|
} // namespace StudioAPI
|
||||||
} // namespace AngelScriptEngine
|
|
||||||
} // namespace Deer
|
} // namespace Deer
|
||||||
@ -1,10 +1,9 @@
|
|||||||
#include "DeerStudio/AngelScriptEngine/AngelScriptRegisters.h"
|
|
||||||
#include "DeerStudio/StudioAPI/Resources.h"
|
#include "DeerStudio/StudioAPI/Resources.h"
|
||||||
|
|
||||||
#include "DeerRender/Resource.h"
|
#include "DeerRender/Resource.h"
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace AngelScriptEngine {
|
namespace StudioAPI {
|
||||||
template <class T>
|
template <class T>
|
||||||
void registerResourceBasics(const char* objName) {
|
void registerResourceBasics(const char* objName) {
|
||||||
REGISTER_OBJECT_METHOD(objName, "bool isValid() const", StudioAPI::APIResource<T>, isValid);
|
REGISTER_OBJECT_METHOD(objName, "bool isValid() const", StudioAPI::APIResource<T>, isValid);
|
||||||
@ -12,9 +11,9 @@ namespace Deer {
|
|||||||
REGISTER_OBJECT_METHOD(objName, "string get_path() const property", StudioAPI::APIResource<T>, getPath);
|
REGISTER_OBJECT_METHOD(objName, "string get_path() const property", StudioAPI::APIResource<T>, getPath);
|
||||||
REGISTER_OBJECT_METHOD(objName, "int get_resourceId() const property", StudioAPI::APIResource<T>, getResourceId);
|
REGISTER_OBJECT_METHOD(objName, "int get_resourceId() const property", StudioAPI::APIResource<T>, getResourceId);
|
||||||
}
|
}
|
||||||
} // namespace AngelScriptEngine
|
} // namespace StudioAPI
|
||||||
|
|
||||||
void AngelScriptEngine::registerResourceStructs() {
|
void StudioAPI::registerResourceStructs() {
|
||||||
scriptEngine->SetDefaultNamespace("");
|
scriptEngine->SetDefaultNamespace("");
|
||||||
AS_CHECK(scriptEngine->RegisterObjectType("GPUMesh", sizeof(StudioAPI::APIResource<GPUMesh>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits<StudioAPI::APIResource<GPUMesh>>()));
|
AS_CHECK(scriptEngine->RegisterObjectType("GPUMesh", sizeof(StudioAPI::APIResource<GPUMesh>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits<StudioAPI::APIResource<GPUMesh>>()));
|
||||||
AS_CHECK(scriptEngine->RegisterObjectType("Shader", sizeof(StudioAPI::APIResource<Shader>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits<StudioAPI::APIResource<Shader>>()));
|
AS_CHECK(scriptEngine->RegisterObjectType("Shader", sizeof(StudioAPI::APIResource<Shader>), asOBJ_VALUE | asOBJ_POD | asOBJ_APP_CLASS_ALLINTS | asGetTypeTraits<StudioAPI::APIResource<Shader>>()));
|
||||||
@ -28,7 +27,7 @@ namespace Deer {
|
|||||||
scriptEngine->RegisterEnumValue("ResourceType", "Texture", (int)StudioAPI::ResourceType::TEXTURE);
|
scriptEngine->RegisterEnumValue("ResourceType", "Texture", (int)StudioAPI::ResourceType::TEXTURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AngelScriptEngine::registerResourceFunctions() {
|
void StudioAPI::registerResourceFunctions() {
|
||||||
registerResourceBasics<GPUMesh>("GPUMesh");
|
registerResourceBasics<GPUMesh>("GPUMesh");
|
||||||
registerResourceBasics<Shader>("Shader");
|
registerResourceBasics<Shader>("Shader");
|
||||||
registerResourceBasics<Texture>("Texture");
|
registerResourceBasics<Texture>("Texture");
|
||||||
@ -2,6 +2,7 @@
|
|||||||
#include "DeerStudio/AngelScriptEngine/AngelScriptRegisters.h"
|
#include "DeerStudio/AngelScriptEngine/AngelScriptRegisters.h"
|
||||||
#include "DeerStudio/StudioAPI/Layout.h"
|
#include "DeerStudio/StudioAPI/Layout.h"
|
||||||
#include "DeerStudio/StudioAPI/Menu.h"
|
#include "DeerStudio/StudioAPI/Menu.h"
|
||||||
|
#include "DeerStudio/StudioAPI/Resources.h"
|
||||||
#include "imgui.h"
|
#include "imgui.h"
|
||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
@ -6,7 +6,6 @@
|
|||||||
|
|
||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace StudioAPI {
|
namespace StudioAPI {
|
||||||
|
|
||||||
void errorCallback_angelscript(const asSMessageInfo* msg, void* param) {
|
void errorCallback_angelscript(const asSMessageInfo* msg, void* param) {
|
||||||
if (msg->type == asMSGTYPE_WARNING) {
|
if (msg->type == asMSGTYPE_WARNING) {
|
||||||
DEER_EDITOR_ENGINE_WARN("{0}:{1}:{2}) : {3}", msg->section,
|
DEER_EDITOR_ENGINE_WARN("{0}:{1}:{2}) : {3}", msg->section,
|
||||||
@ -17,7 +16,7 @@ namespace Deer {
|
|||||||
} else if (msg->type == asMSGTYPE_ERROR) {
|
} else if (msg->type == asMSGTYPE_ERROR) {
|
||||||
DEER_EDITOR_ENGINE_ERROR("{0}:{1}:{2}) : {3}", msg->section,
|
DEER_EDITOR_ENGINE_ERROR("{0}:{1}:{2}) : {3}", msg->section,
|
||||||
msg->row, msg->col, msg->message);
|
msg->row, msg->col, msg->message);
|
||||||
}else {
|
} else {
|
||||||
DEER_EDITOR_ENGINE_INFO("{0}:{1}:{2}) : {3}", msg->section,
|
DEER_EDITOR_ENGINE_INFO("{0}:{1}:{2}) : {3}", msg->section,
|
||||||
msg->row, msg->col, msg->message);
|
msg->row, msg->col, msg->message);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -23,7 +23,7 @@ namespace Deer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CScriptArray* dividePath_angelscript(std::string& path_s) {
|
CScriptArray* dividePath_angelscript(std::string& path_s) {
|
||||||
CScriptArray* array = CScriptArray::Create(AngelScriptEngine::arrayStringBaseType);
|
CScriptArray* array = CScriptArray::Create(StudioAPI::arrayStringBaseType);
|
||||||
|
|
||||||
Path path_p(path_s);
|
Path path_p(path_s);
|
||||||
for (const auto& part : path_p) {
|
for (const auto& part : path_p) {
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
#include "DeerStudio/AngelScriptEngine.h"
|
#include "DeerStudio/AngelScriptEngine.h"
|
||||||
|
|
||||||
#include "DeerRender/Components.h"
|
#include "DeerRender/Components.h"
|
||||||
|
#include "DeerRender/Engine.h"
|
||||||
#include "DeerRender/EntityEnviroment.h"
|
#include "DeerRender/EntityEnviroment.h"
|
||||||
#include "DeerRender/World.h"
|
#include "DeerRender/World.h"
|
||||||
|
|
||||||
@ -9,7 +10,7 @@
|
|||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#define GET_ENV(env) ((env < 0) ? World::environment : Deer::Resource<EntityEnvironment>::unsafeFromId(environmentId).getData())
|
#define GET_ENV(env) ((env < 0) ? *(Engine::getMainWorld().entityEnvironment.get()) : Deer::Resource<EntityEnvironment>::unsafeFromId(environmentId).getData())
|
||||||
|
|
||||||
#define GET_ENTITY(env, id) GET_ENV(env).getEntity(id)
|
#define GET_ENTITY(env, id) GET_ENV(env).getEntity(id)
|
||||||
#define GET_MESH_COMPONENT(env, id) \
|
#define GET_MESH_COMPONENT(env, id) \
|
||||||
@ -46,19 +47,19 @@ namespace Deer {
|
|||||||
|
|
||||||
EntityStruct::EntityStruct(uint16_t _entId, int32_t _envId) : EntityHandleStruct(_entId, _envId) {}
|
EntityStruct::EntityStruct(uint16_t _entId, int32_t _envId) : EntityHandleStruct(_entId, _envId) {}
|
||||||
|
|
||||||
EntityEnvironment* EntityHandleStruct::getEntityEntityEnvironment() {
|
EntityEnvironment* EntityHandleStruct::getEntityEnvironment() {
|
||||||
if (environmentId < 0)
|
if (environmentId < 0)
|
||||||
return &World::environment;
|
return Engine::getMainWorld().entityEnvironment.get();
|
||||||
return &Resource<EntityEnvironment>::unsafeFromId(environmentId).getData();
|
return &Resource<EntityEnvironment>::unsafeFromId(environmentId).getData();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EntityHandleStruct::assertEntity(const char* funcName) {
|
bool EntityHandleStruct::assertEntity(const char* funcName) {
|
||||||
EntityEnvironment* env = getEntityEntityEnvironment();
|
EntityEnvironment* env = getEntityEnvironment();
|
||||||
if (!env->entityExists(entityId)) {
|
if (!env->entityExists(entityId)) {
|
||||||
DEER_EDITOR_ENGINE_ERROR(
|
DEER_EDITOR_ENGINE_ERROR(
|
||||||
"Error, invalid entity calling {0}, entityId : {1}, environmentId : {2}",
|
"Error, invalid entity calling {0}, entityId : {1}, environmentId : {2}",
|
||||||
funcName, entityId, environmentId);
|
funcName, entityId, environmentId);
|
||||||
AngelScriptEngine::raiseError();
|
StudioAPI::raiseError();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
@ -67,7 +68,7 @@ namespace Deer {
|
|||||||
std::string EntityStruct::getName() {
|
std::string EntityStruct::getName() {
|
||||||
ASSERT_ENTITY("getName()", return "NULL");
|
ASSERT_ENTITY("getName()", return "NULL");
|
||||||
|
|
||||||
return GET_ENTITY(environmentId, entityId).getComponent<TagComponent>().tag;
|
return ((environmentId < 0) ? *Engine::getMainWorld().entityEnvironment.get() : Deer::Resource<EntityEnvironment>::unsafeFromId(environmentId).getData()).getEntity(entityId).getComponent<TagComponent>().tag;
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityStruct::setName(std::string& name) {
|
void EntityStruct::setName(std::string& name) {
|
||||||
@ -93,7 +94,7 @@ namespace Deer {
|
|||||||
bool EntityStruct::exists() {
|
bool EntityStruct::exists() {
|
||||||
ASSERT_ENTITY("exists()", return false);
|
ASSERT_ENTITY("exists()", return false);
|
||||||
|
|
||||||
return World::environment.entityExists(entityId);
|
return Engine::getMainWorld().entityEnvironment->entityExists(entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void EntityStruct::setParent(EntityHandleStruct parent_struct) {
|
void EntityStruct::setParent(EntityHandleStruct parent_struct) {
|
||||||
@ -198,7 +199,7 @@ namespace Deer {
|
|||||||
|
|
||||||
EntityEnvironment* env;
|
EntityEnvironment* env;
|
||||||
if (environmentId < 0)
|
if (environmentId < 0)
|
||||||
env = &World::environment;
|
env = Engine::getMainWorld().entityEnvironment.get();
|
||||||
else
|
else
|
||||||
env = &Resource<EntityEnvironment>::unsafeFromId(environmentId).getData();
|
env = &Resource<EntityEnvironment>::unsafeFromId(environmentId).getData();
|
||||||
|
|
||||||
@ -211,7 +212,7 @@ namespace Deer {
|
|||||||
funcName, ent.getComponent<TagComponent>().tag.c_str(),
|
funcName, ent.getComponent<TagComponent>().tag.c_str(),
|
||||||
entityId);
|
entityId);
|
||||||
|
|
||||||
AngelScriptEngine::raiseError();
|
StudioAPI::raiseError();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -230,7 +231,7 @@ namespace Deer {
|
|||||||
"Error while executing EntityChild.getChild(..), id {0} is "
|
"Error while executing EntityChild.getChild(..), id {0} is "
|
||||||
"invalid for child count of {1}",
|
"invalid for child count of {1}",
|
||||||
i, rc.getChildCount());
|
i, rc.getChildCount());
|
||||||
AngelScriptEngine::raiseError();
|
StudioAPI::raiseError();
|
||||||
|
|
||||||
return EntityStruct(0);
|
return EntityStruct(0);
|
||||||
}
|
}
|
||||||
@ -241,7 +242,7 @@ namespace Deer {
|
|||||||
EntityHandleStruct EntityStruct::createChild(std::string& name) {
|
EntityHandleStruct EntityStruct::createChild(std::string& name) {
|
||||||
ASSERT_ENTITY("createChild()", return *this);
|
ASSERT_ENTITY("createChild()", return *this);
|
||||||
|
|
||||||
EntityEnvironment* entityEnv = getEntityEntityEnvironment();
|
EntityEnvironment* entityEnv = getEntityEnvironment();
|
||||||
|
|
||||||
Entity& newEnt = entityEnv->createEntity(name);
|
Entity& newEnt = entityEnv->createEntity(name);
|
||||||
Entity& me = GET_ENTITY(environmentId, entityId);
|
Entity& me = GET_ENTITY(environmentId, entityId);
|
||||||
@ -264,7 +265,7 @@ namespace Deer {
|
|||||||
.tag.c_str(),
|
.tag.c_str(),
|
||||||
entityId);
|
entityId);
|
||||||
|
|
||||||
AngelScriptEngine::raiseError();
|
StudioAPI::raiseError();
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@ -313,7 +314,7 @@ namespace Deer {
|
|||||||
.tag.c_str(),
|
.tag.c_str(),
|
||||||
entityId);
|
entityId);
|
||||||
|
|
||||||
AngelScriptEngine::raiseError();
|
StudioAPI::raiseError();
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@ -362,7 +363,7 @@ namespace Deer {
|
|||||||
.tag.c_str(),
|
.tag.c_str(),
|
||||||
entityId);
|
entityId);
|
||||||
|
|
||||||
AngelScriptEngine::raiseError();
|
StudioAPI::raiseError();
|
||||||
}
|
}
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
@ -437,7 +438,7 @@ namespace Deer {
|
|||||||
bool ShaderComponentStruct::assertShaderComponent(const char* funcName) {
|
bool ShaderComponentStruct::assertShaderComponent(const char* funcName) {
|
||||||
if (!assertEntity(funcName))
|
if (!assertEntity(funcName))
|
||||||
return false;
|
return false;
|
||||||
EntityEnvironment* env = getEntityEntityEnvironment();
|
EntityEnvironment* env = getEntityEnvironment();
|
||||||
|
|
||||||
Entity& ent = env->getEntity(entityId);
|
Entity& ent = env->getEntity(entityId);
|
||||||
|
|
||||||
@ -448,7 +449,7 @@ namespace Deer {
|
|||||||
funcName, ent.getComponent<TagComponent>().tag.c_str(),
|
funcName, ent.getComponent<TagComponent>().tag.c_str(),
|
||||||
entityId);
|
entityId);
|
||||||
|
|
||||||
AngelScriptEngine::raiseError();
|
StudioAPI::raiseError();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -488,7 +489,7 @@ namespace Deer {
|
|||||||
bool CameraComponentStruct::assertCameraComponent(const char* funcName) {
|
bool CameraComponentStruct::assertCameraComponent(const char* funcName) {
|
||||||
if (!assertEntity(funcName))
|
if (!assertEntity(funcName))
|
||||||
return false;
|
return false;
|
||||||
EntityEnvironment* env = getEntityEntityEnvironment();
|
EntityEnvironment* env = getEntityEnvironment();
|
||||||
|
|
||||||
Entity& ent = env->getEntity(entityId);
|
Entity& ent = env->getEntity(entityId);
|
||||||
|
|
||||||
@ -499,7 +500,7 @@ namespace Deer {
|
|||||||
funcName, ent.getComponent<TagComponent>().tag.c_str(),
|
funcName, ent.getComponent<TagComponent>().tag.c_str(),
|
||||||
entityId);
|
entityId);
|
||||||
|
|
||||||
AngelScriptEngine::raiseError();
|
StudioAPI::raiseError();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,4 @@
|
|||||||
|
#include "DeerRender/Engine.h"
|
||||||
#include "DeerRender/EntityEnviroment.h"
|
#include "DeerRender/EntityEnviroment.h"
|
||||||
#include "DeerRender/Resource.h"
|
#include "DeerRender/Resource.h"
|
||||||
#include "DeerRender/Tools/Memory.h"
|
#include "DeerRender/Tools/Memory.h"
|
||||||
@ -13,7 +14,7 @@
|
|||||||
namespace Deer {
|
namespace Deer {
|
||||||
namespace StudioAPI {
|
namespace StudioAPI {
|
||||||
// The first element has to allways point to the main scene env
|
// The first element has to allways point to the main scene env
|
||||||
std::vector<EntityEnvironment*> environments{&World::environment};
|
std::vector<EntityEnvironment*> environments;
|
||||||
|
|
||||||
void EntityEnvironmentStruct::render(FrameBufferHandleStruct frameBuffer_handle, WorldCamera& sc) {
|
void EntityEnvironmentStruct::render(FrameBufferHandleStruct frameBuffer_handle, WorldCamera& sc) {
|
||||||
Resource<FrameBuffer> frameBufferResource = Resource<FrameBuffer>::unsafeFromId(frameBuffer_handle.frameBufferId);
|
Resource<FrameBuffer> frameBufferResource = Resource<FrameBuffer>::unsafeFromId(frameBuffer_handle.frameBufferId);
|
||||||
@ -21,7 +22,7 @@ namespace Deer {
|
|||||||
|
|
||||||
EntityEnvironment* envPtr = nullptr;
|
EntityEnvironment* envPtr = nullptr;
|
||||||
if (environmentId < 0) {
|
if (environmentId < 0) {
|
||||||
envPtr = &World::environment;
|
envPtr = Engine::getMainWorld().entityEnvironment.get();
|
||||||
} else {
|
} else {
|
||||||
Resource<EntityEnvironment> environmentResource = Resource<EntityEnvironment>::unsafeFromId(environmentId);
|
Resource<EntityEnvironment> environmentResource = Resource<EntityEnvironment>::unsafeFromId(environmentId);
|
||||||
envPtr = &environmentResource.getData();
|
envPtr = &environmentResource.getData();
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
#include "DeerRender/DataStore.h"
|
|
||||||
#include "DeerRender/Resource.h"
|
#include "DeerRender/Resource.h"
|
||||||
#include "DeerRender/Texture.h"
|
#include "DeerRender/Texture.h"
|
||||||
#include "DeerStudio/EditorDataSource.h"
|
#include "DeerStudio/EditorDataSource.h"
|
||||||
|
|||||||
@ -34,12 +34,12 @@ namespace Deer {
|
|||||||
if (ImGui::TreeNodeEx(txt.c_str(), flags)) {
|
if (ImGui::TreeNodeEx(txt.c_str(), flags)) {
|
||||||
ImGui::PushID(txt.c_str());
|
ImGui::PushID(txt.c_str());
|
||||||
|
|
||||||
if (AngelScriptEngine::scriptContext && AngelScriptEngine::scriptContext->PushState() == asSUCCESS) {
|
if (StudioAPI::scriptContext && StudioAPI::scriptContext->PushState() == asSUCCESS) {
|
||||||
|
|
||||||
AS_CHECK_ADDITIONAL_INFO(AngelScriptEngine::scriptContext->Prepare(&func), func.GetDeclaration());
|
AS_CHECK_ADDITIONAL_INFO(StudioAPI::scriptContext->Prepare(&func), func.GetDeclaration());
|
||||||
AS_CHECK_ADDITIONAL_INFO(AngelScriptEngine::scriptContext->Execute(), func.GetDeclaration());
|
AS_CHECK_ADDITIONAL_INFO(StudioAPI::scriptContext->Execute(), func.GetDeclaration());
|
||||||
|
|
||||||
AngelScriptEngine::scriptContext->PopState();
|
StudioAPI::scriptContext->PopState();
|
||||||
} else {
|
} else {
|
||||||
ImGui::Text("Something failed");
|
ImGui::Text("Something failed");
|
||||||
}
|
}
|
||||||
@ -68,13 +68,13 @@ namespace Deer {
|
|||||||
if (ImGui::TreeNodeEx(txt.c_str(), flags)) {
|
if (ImGui::TreeNodeEx(txt.c_str(), flags)) {
|
||||||
ImGui::Dummy(ImVec2(0, 10));
|
ImGui::Dummy(ImVec2(0, 10));
|
||||||
ImGui::PushID(txt.c_str());
|
ImGui::PushID(txt.c_str());
|
||||||
if (AngelScriptEngine::scriptContext &&
|
if (StudioAPI::scriptContext &&
|
||||||
AngelScriptEngine::scriptContext->PushState() == asSUCCESS) {
|
StudioAPI::scriptContext->PushState() == asSUCCESS) {
|
||||||
|
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Prepare(func));
|
AS_CHECK(StudioAPI::scriptContext->Prepare(func));
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Execute());
|
AS_CHECK(StudioAPI::scriptContext->Execute());
|
||||||
|
|
||||||
AngelScriptEngine::scriptContext->PopState();
|
StudioAPI::scriptContext->PopState();
|
||||||
} else {
|
} else {
|
||||||
ImGui::Text("Something failed");
|
ImGui::Text("Something failed");
|
||||||
}
|
}
|
||||||
@ -105,13 +105,13 @@ namespace Deer {
|
|||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding,
|
||||||
ImVec2(10, 10));
|
ImVec2(10, 10));
|
||||||
if (ImGui::BeginPopupContextItem(txt.c_str())) {
|
if (ImGui::BeginPopupContextItem(txt.c_str())) {
|
||||||
if (AngelScriptEngine::scriptContext &&
|
if (StudioAPI::scriptContext &&
|
||||||
AngelScriptEngine::scriptContext->PushState() == asSUCCESS) {
|
StudioAPI::scriptContext->PushState() == asSUCCESS) {
|
||||||
|
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Prepare(menu));
|
AS_CHECK(StudioAPI::scriptContext->Prepare(menu));
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Execute());
|
AS_CHECK(StudioAPI::scriptContext->Execute());
|
||||||
|
|
||||||
AngelScriptEngine::scriptContext->PopState();
|
StudioAPI::scriptContext->PopState();
|
||||||
} else {
|
} else {
|
||||||
ImGui::Text("Something failed");
|
ImGui::Text("Something failed");
|
||||||
}
|
}
|
||||||
@ -121,13 +121,13 @@ namespace Deer {
|
|||||||
|
|
||||||
ImGui::Dummy(ImVec2(0, 10));
|
ImGui::Dummy(ImVec2(0, 10));
|
||||||
ImGui::PushID(txt.c_str());
|
ImGui::PushID(txt.c_str());
|
||||||
if (AngelScriptEngine::scriptContext &&
|
if (StudioAPI::scriptContext &&
|
||||||
AngelScriptEngine::scriptContext->PushState() == asSUCCESS) {
|
StudioAPI::scriptContext->PushState() == asSUCCESS) {
|
||||||
|
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Prepare(func));
|
AS_CHECK(StudioAPI::scriptContext->Prepare(func));
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Execute());
|
AS_CHECK(StudioAPI::scriptContext->Execute());
|
||||||
|
|
||||||
AngelScriptEngine::scriptContext->PopState();
|
StudioAPI::scriptContext->PopState();
|
||||||
} else {
|
} else {
|
||||||
ImGui::Text("Something failed");
|
ImGui::Text("Something failed");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,13 +17,13 @@ namespace Deer {
|
|||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10, 10));
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10, 10));
|
||||||
if (ImGui::BeginPopupContextItem(menu_id.c_str())) {
|
if (ImGui::BeginPopupContextItem(menu_id.c_str())) {
|
||||||
|
|
||||||
if (AngelScriptEngine::scriptContext &&
|
if (StudioAPI::scriptContext &&
|
||||||
AngelScriptEngine::scriptContext->PushState() == asSUCCESS) {
|
StudioAPI::scriptContext->PushState() == asSUCCESS) {
|
||||||
|
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Prepare(func));
|
AS_CHECK(StudioAPI::scriptContext->Prepare(func));
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Execute());
|
AS_CHECK(StudioAPI::scriptContext->Execute());
|
||||||
|
|
||||||
AngelScriptEngine::scriptContext->PopState();
|
StudioAPI::scriptContext->PopState();
|
||||||
} else {
|
} else {
|
||||||
ImGui::Text("Something failed");
|
ImGui::Text("Something failed");
|
||||||
}
|
}
|
||||||
@ -37,13 +37,13 @@ namespace Deer {
|
|||||||
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10, 10));
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10, 10));
|
||||||
if (ImGui::BeginPopupContextWindow(menu_id.c_str())) {
|
if (ImGui::BeginPopupContextWindow(menu_id.c_str())) {
|
||||||
|
|
||||||
if (AngelScriptEngine::scriptContext &&
|
if (StudioAPI::scriptContext &&
|
||||||
AngelScriptEngine::scriptContext->PushState() == asSUCCESS) {
|
StudioAPI::scriptContext->PushState() == asSUCCESS) {
|
||||||
|
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Prepare(func));
|
AS_CHECK(StudioAPI::scriptContext->Prepare(func));
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Execute());
|
AS_CHECK(StudioAPI::scriptContext->Execute());
|
||||||
|
|
||||||
AngelScriptEngine::scriptContext->PopState();
|
StudioAPI::scriptContext->PopState();
|
||||||
} else {
|
} else {
|
||||||
ImGui::Text("Something failed");
|
ImGui::Text("Something failed");
|
||||||
}
|
}
|
||||||
@ -91,16 +91,16 @@ namespace Deer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AngelScriptEngine::scriptContext &&
|
if (StudioAPI::scriptContext &&
|
||||||
AngelScriptEngine::scriptContext->PushState() == asSUCCESS) {
|
StudioAPI::scriptContext->PushState() == asSUCCESS) {
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Prepare(func));
|
AS_CHECK(StudioAPI::scriptContext->Prepare(func));
|
||||||
|
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->SetArgObject(
|
AS_CHECK(StudioAPI::scriptContext->SetArgObject(
|
||||||
0, MenuContext::payload));
|
0, MenuContext::payload));
|
||||||
|
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Execute());
|
AS_CHECK(StudioAPI::scriptContext->Execute());
|
||||||
|
|
||||||
AngelScriptEngine::scriptContext->PopState();
|
StudioAPI::scriptContext->PopState();
|
||||||
} else {
|
} else {
|
||||||
ImGui::Text("Something failed");
|
ImGui::Text("Something failed");
|
||||||
}
|
}
|
||||||
@ -140,12 +140,12 @@ namespace Deer {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (AngelScriptEngine::scriptContext &&
|
if (StudioAPI::scriptContext &&
|
||||||
AngelScriptEngine::scriptContext->PushState() == asSUCCESS) {
|
StudioAPI::scriptContext->PushState() == asSUCCESS) {
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Prepare(func));
|
AS_CHECK(StudioAPI::scriptContext->Prepare(func));
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Execute());
|
AS_CHECK(StudioAPI::scriptContext->Execute());
|
||||||
|
|
||||||
AngelScriptEngine::scriptContext->PopState();
|
StudioAPI::scriptContext->PopState();
|
||||||
} else {
|
} else {
|
||||||
ImGui::Text("Something failed");
|
ImGui::Text("Something failed");
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,7 +16,7 @@ namespace Deer {
|
|||||||
|
|
||||||
if (extension == ".obj" || extension == ".fbx" || extension == ".dae" ||
|
if (extension == ".obj" || extension == ".fbx" || extension == ".dae" ||
|
||||||
extension == ".3ds" || extension == ".ply" || extension == ".stl" ||
|
extension == ".3ds" || extension == ".ply" || extension == ".stl" ||
|
||||||
extension == ".glb" || extension == ".gltf"|| extension == ".mtl") {
|
extension == ".glb" || extension == ".gltf" || extension == ".mtl") {
|
||||||
return ResourceType::MESH;
|
return ResourceType::MESH;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -30,7 +30,7 @@ namespace Deer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
CScriptArray* getResourceFolders(std::string& path_s) {
|
CScriptArray* getResourceFolders(std::string& path_s) {
|
||||||
CScriptArray* array = CScriptArray::Create(AngelScriptEngine::arrayStringBaseType);
|
CScriptArray* array = CScriptArray::Create(StudioAPI::arrayStringBaseType);
|
||||||
|
|
||||||
Path path_p = Path("Resources") / Path(path_s).lexically_normal();
|
Path path_p = Path("Resources") / Path(path_s).lexically_normal();
|
||||||
try {
|
try {
|
||||||
@ -50,7 +50,7 @@ namespace Deer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
CScriptArray* getResourceFiles(std::string& path_s) {
|
CScriptArray* getResourceFiles(std::string& path_s) {
|
||||||
CScriptArray* array = CScriptArray::Create(AngelScriptEngine::arrayStringBaseType);
|
CScriptArray* array = CScriptArray::Create(StudioAPI::arrayStringBaseType);
|
||||||
|
|
||||||
Path path_p = Path("Resources") / Path(path_s).lexically_normal();
|
Path path_p = Path("Resources") / Path(path_s).lexically_normal();
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -90,8 +90,7 @@ namespace Deer {
|
|||||||
return ImGui::Button(txt.c_str());
|
return ImGui::Button(txt.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cartIconButton(const std::string& label, const std::string& icon, int iconSize, int width)
|
bool cartIconButton(const std::string& label, const std::string& icon, int iconSize, int width) {
|
||||||
{
|
|
||||||
ImGui::BeginGroup();
|
ImGui::BeginGroup();
|
||||||
|
|
||||||
int offset = 16;
|
int offset = 16;
|
||||||
@ -111,39 +110,34 @@ namespace Deer {
|
|||||||
// Background
|
// Background
|
||||||
dl->AddRectFilled(
|
dl->AddRectFilled(
|
||||||
p, q,
|
p, q,
|
||||||
hovered ? IM_COL32(255,255,255,30) : IM_COL32(255,255,255,10),
|
hovered ? IM_COL32(255, 255, 255, 30) : IM_COL32(255, 255, 255, 10),
|
||||||
4.0f
|
4.0f);
|
||||||
);
|
|
||||||
|
|
||||||
// Center icon horizontally
|
// Center icon horizontally
|
||||||
ImVec2 iconPos(
|
ImVec2 iconPos(
|
||||||
p.x + (itemWidth - iconSize) * 0.5f,
|
p.x + (itemWidth - iconSize) * 0.5f,
|
||||||
p.y + 2.0f + offset
|
p.y + 2.0f + offset);
|
||||||
);
|
|
||||||
|
|
||||||
int texId = StudioAPI::getIconId("Icons/" + icon);
|
int texId = StudioAPI::getIconId("Icons/" + icon);
|
||||||
dl->AddImage(
|
dl->AddImage(
|
||||||
(ImTextureID)texId,
|
(ImTextureID)texId,
|
||||||
iconPos,
|
iconPos,
|
||||||
ImVec2(iconPos.x + iconSize, iconPos.y + iconSize),
|
ImVec2(iconPos.x + iconSize, iconPos.y + iconSize),
|
||||||
ImVec2(0,1),
|
ImVec2(0, 1),
|
||||||
ImVec2(1,0)
|
ImVec2(1, 0));
|
||||||
);
|
|
||||||
|
|
||||||
// Center text
|
// Center text
|
||||||
ImVec2 textSize = ImGui::CalcTextSize(label.c_str());
|
ImVec2 textSize = ImGui::CalcTextSize(label.c_str());
|
||||||
ImVec2 textPos(
|
ImVec2 textPos(
|
||||||
p.x + (itemWidth - textSize.x) * 0.5f,
|
p.x + (itemWidth - textSize.x) * 0.5f,
|
||||||
iconPos.y + iconSize + 2.0f
|
iconPos.y + iconSize + 2.0f);
|
||||||
);
|
|
||||||
dl->AddText(textPos, ImGui::GetColorU32(ImGuiCol_Text), label.c_str());
|
dl->AddText(textPos, ImGui::GetColorU32(ImGuiCol_Text), label.c_str());
|
||||||
|
|
||||||
ImGui::EndGroup();
|
ImGui::EndGroup();
|
||||||
return pressed;
|
return pressed;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cartIconButton_frameBuffer(const std::string& label, FrameBufferHandleStruct icon, int iconSize, int width)
|
bool cartIconButton_frameBuffer(const std::string& label, FrameBufferHandleStruct icon, int iconSize, int width) {
|
||||||
{
|
|
||||||
ImGui::BeginGroup();
|
ImGui::BeginGroup();
|
||||||
|
|
||||||
int offset = 16;
|
int offset = 16;
|
||||||
@ -163,15 +157,13 @@ namespace Deer {
|
|||||||
// Background
|
// Background
|
||||||
dl->AddRectFilled(
|
dl->AddRectFilled(
|
||||||
p, q,
|
p, q,
|
||||||
hovered ? IM_COL32(255,255,255,30) : IM_COL32(255,255,255,10),
|
hovered ? IM_COL32(255, 255, 255, 30) : IM_COL32(255, 255, 255, 10),
|
||||||
4.0f
|
4.0f);
|
||||||
);
|
|
||||||
|
|
||||||
// Center icon horizontally
|
// Center icon horizontally
|
||||||
ImVec2 iconPos(
|
ImVec2 iconPos(
|
||||||
p.x + (itemWidth - iconSize) * 0.5f,
|
p.x + (itemWidth - iconSize) * 0.5f,
|
||||||
p.y + 2.0f + offset
|
p.y + 2.0f + offset);
|
||||||
);
|
|
||||||
|
|
||||||
FrameBuffer& frameBuffer = Resource<FrameBuffer>::unsafeFromId(icon.frameBufferId).getData();
|
FrameBuffer& frameBuffer = Resource<FrameBuffer>::unsafeFromId(icon.frameBufferId).getData();
|
||||||
frameBuffer.bind();
|
frameBuffer.bind();
|
||||||
@ -180,17 +172,15 @@ namespace Deer {
|
|||||||
(ImTextureID)texId,
|
(ImTextureID)texId,
|
||||||
iconPos,
|
iconPos,
|
||||||
ImVec2(iconPos.x + iconSize, iconPos.y + iconSize),
|
ImVec2(iconPos.x + iconSize, iconPos.y + iconSize),
|
||||||
ImVec2(0,1),
|
ImVec2(0, 1),
|
||||||
ImVec2(1,0)
|
ImVec2(1, 0));
|
||||||
);
|
|
||||||
frameBuffer.unbind();
|
frameBuffer.unbind();
|
||||||
|
|
||||||
// Center text
|
// Center text
|
||||||
ImVec2 textSize = ImGui::CalcTextSize(label.c_str());
|
ImVec2 textSize = ImGui::CalcTextSize(label.c_str());
|
||||||
ImVec2 textPos(
|
ImVec2 textPos(
|
||||||
p.x + (itemWidth - textSize.x) * 0.5f,
|
p.x + (itemWidth - textSize.x) * 0.5f,
|
||||||
iconPos.y + iconSize + 2.0f
|
iconPos.y + iconSize + 2.0f);
|
||||||
);
|
|
||||||
dl->AddText(textPos, ImGui::GetColorU32(ImGuiCol_Text), label.c_str());
|
dl->AddText(textPos, ImGui::GetColorU32(ImGuiCol_Text), label.c_str());
|
||||||
|
|
||||||
ImGui::EndGroup();
|
ImGui::EndGroup();
|
||||||
@ -247,7 +237,7 @@ namespace Deer {
|
|||||||
|
|
||||||
if (iconId < 0) {
|
if (iconId < 0) {
|
||||||
DEER_EDITOR_ENGINE_ERROR("Invalid icon name {0}", name.c_str());
|
DEER_EDITOR_ENGINE_ERROR("Invalid icon name {0}", name.c_str());
|
||||||
AngelScriptEngine::raiseError();
|
StudioAPI::raiseError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,7 +250,7 @@ namespace Deer {
|
|||||||
}
|
}
|
||||||
void drawIconHighlight_resource(Resource<Texture> texture, int size) {
|
void drawIconHighlight_resource(Resource<Texture> texture, int size) {
|
||||||
int iconId = texture.getData().getTextureID();
|
int iconId = texture.getData().getTextureID();
|
||||||
ImGui::Image((void*)(uint64_t)iconId, ImVec2(size, size), ImVec2(0, 1), ImVec2(1, 0), ImVec4(0.5f, 0.6f, 0.8f, 1.0f), ImVec4(0,0,0,0));
|
ImGui::Image((void*)(uint64_t)iconId, ImVec2(size, size), ImVec2(0, 1), ImVec2(1, 0), ImVec4(0.5f, 0.6f, 0.8f, 1.0f), ImVec4(0, 0, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawIconHighlight(std::string& name, int size) {
|
void drawIconHighlight(std::string& name, int size) {
|
||||||
@ -268,11 +258,11 @@ namespace Deer {
|
|||||||
|
|
||||||
if (iconId < 0) {
|
if (iconId < 0) {
|
||||||
DEER_EDITOR_ENGINE_ERROR("Invalid icon name {0}", name.c_str());
|
DEER_EDITOR_ENGINE_ERROR("Invalid icon name {0}", name.c_str());
|
||||||
AngelScriptEngine::raiseError();
|
StudioAPI::raiseError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Image((void*)(uint64_t)iconId, ImVec2(size, size), ImVec2(0, 1), ImVec2(1, 0), ImVec4(0.5f, 0.6f, 0.8f, 1.0f), ImVec4(0,0,0,0));
|
ImGui::Image((void*)(uint64_t)iconId, ImVec2(size, size), ImVec2(0, 1), ImVec2(1, 0), ImVec4(0.5f, 0.6f, 0.8f, 1.0f), ImVec4(0, 0, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawFrameBuffer(FrameBufferHandleStruct frameBuffer_handle, int sizeX, int sizeY) {
|
void drawFrameBuffer(FrameBufferHandleStruct frameBuffer_handle, int sizeX, int sizeY) {
|
||||||
@ -327,7 +317,7 @@ namespace Deer {
|
|||||||
int iconId = StudioAPI::getIconId("Icons/" + name);
|
int iconId = StudioAPI::getIconId("Icons/" + name);
|
||||||
if (iconId < 0) {
|
if (iconId < 0) {
|
||||||
DEER_EDITOR_ENGINE_ERROR("Invalid icon name {0}", name.c_str());
|
DEER_EDITOR_ENGINE_ERROR("Invalid icon name {0}", name.c_str());
|
||||||
AngelScriptEngine::raiseError();
|
StudioAPI::raiseError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -365,7 +355,7 @@ namespace Deer {
|
|||||||
int iconId = StudioAPI::getIconId("Icons/" + name);
|
int iconId = StudioAPI::getIconId("Icons/" + name);
|
||||||
if (iconId < 0) {
|
if (iconId < 0) {
|
||||||
DEER_EDITOR_ENGINE_ERROR("Invalid icon name {0}", name.c_str());
|
DEER_EDITOR_ENGINE_ERROR("Invalid icon name {0}", name.c_str());
|
||||||
AngelScriptEngine::raiseError();
|
StudioAPI::raiseError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,13 +384,13 @@ namespace Deer {
|
|||||||
|
|
||||||
void subMenu(std::string& txt, asIScriptFunction* func) {
|
void subMenu(std::string& txt, asIScriptFunction* func) {
|
||||||
if (ImGui::BeginMenu(txt.c_str())) {
|
if (ImGui::BeginMenu(txt.c_str())) {
|
||||||
if (AngelScriptEngine::scriptContext &&
|
if (StudioAPI::scriptContext &&
|
||||||
AngelScriptEngine::scriptContext->PushState() == asSUCCESS) {
|
StudioAPI::scriptContext->PushState() == asSUCCESS) {
|
||||||
|
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Prepare(func));
|
AS_CHECK(StudioAPI::scriptContext->Prepare(func));
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Execute());
|
AS_CHECK(StudioAPI::scriptContext->Execute());
|
||||||
|
|
||||||
AngelScriptEngine::scriptContext->PopState();
|
StudioAPI::scriptContext->PopState();
|
||||||
}
|
}
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
@ -440,14 +430,14 @@ namespace Deer {
|
|||||||
if (ImGui::AcceptDragDropPayload(id.c_str()) &&
|
if (ImGui::AcceptDragDropPayload(id.c_str()) &&
|
||||||
DragDropPayload::payload) {
|
DragDropPayload::payload) {
|
||||||
|
|
||||||
if (AngelScriptEngine::scriptContext &&
|
if (StudioAPI::scriptContext &&
|
||||||
AngelScriptEngine::scriptContext->PushState() == asSUCCESS) {
|
StudioAPI::scriptContext->PushState() == asSUCCESS) {
|
||||||
|
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Prepare(func));
|
AS_CHECK(StudioAPI::scriptContext->Prepare(func));
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->SetArgObject(0, DragDropPayload::payload));
|
AS_CHECK(StudioAPI::scriptContext->SetArgObject(0, DragDropPayload::payload));
|
||||||
AS_CHECK(AngelScriptEngine::scriptContext->Execute());
|
AS_CHECK(StudioAPI::scriptContext->Execute());
|
||||||
|
|
||||||
AngelScriptEngine::scriptContext->PopState();
|
StudioAPI::scriptContext->PopState();
|
||||||
}
|
}
|
||||||
|
|
||||||
DragDropPayload::payload->Release();
|
DragDropPayload::payload->Release();
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
class RenderService : Service {
|
class RenderService : Service {
|
||||||
EntityEnvir nment env;
|
EntityEnvironment env;
|
||||||
WorldCamera sceneCamera;
|
WorldCamera sceneCamera;
|
||||||
MeshComponent meshC;
|
MeshComponent meshC;
|
||||||
Entity child;
|
Entity child;
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
class ViewportPanel : Panel {
|
class ViewportPanel : Panel {
|
||||||
FrameBuffer frameBuffer;
|
FrameBuffer frameBuffer;
|
||||||
WorldCamera sceneCamera;
|
WorldCamera sceneCamera;
|
||||||
EntityEnvir nment mainEnv;
|
EntityEnvironment env;
|
||||||
|
|
||||||
float pitch = 0;
|
float pitch = 0;
|
||||||
float yaw = 0;
|
float yaw = 0;
|
||||||
@ -21,7 +21,7 @@ class ViewportPanel : Panel {
|
|||||||
frameBuffer.clearRGBA(0, 0, 0, 255);
|
frameBuffer.clearRGBA(0, 0, 0, 255);
|
||||||
|
|
||||||
sceneCamera.camera.aspect = float(x) / y;
|
sceneCamera.camera.aspect = float(x) / y;
|
||||||
mainEnv.render(frameBuffer, sceneCamera);
|
env.render(frameBuffer, sceneCamera);
|
||||||
|
|
||||||
UI::drawFrameBufferCentered(frameBuffer, x, y);
|
UI::drawFrameBufferCentered(frameBuffer, x, y);
|
||||||
if (!UI::isPanelActive())
|
if (!UI::isPanelActive())
|
||||||
@ -70,7 +70,7 @@ class ViewportPanel : Panel {
|
|||||||
|
|
||||||
void init() {
|
void init() {
|
||||||
frameBuffer = Resource::createLoadRGBA8FrameBuffer("MainFrameBuffer", 1000, 1000);
|
frameBuffer = Resource::createLoadRGBA8FrameBuffer("MainFrameBuffer", 1000, 1000);
|
||||||
mainEnv = Resource::getMainEntityEnvironment();
|
env = Resource::getMainEntityEnvironment();
|
||||||
|
|
||||||
sceneCamera.transform.position = vec3(0, 1, -2);
|
sceneCamera.transform.position = vec3(0, 1, -2);
|
||||||
sceneCamera.camera.nearZ = 0.1;
|
sceneCamera.camera.nearZ = 0.1;
|
||||||
|
|||||||
@ -16,7 +16,7 @@ Collapsed=0
|
|||||||
|
|
||||||
[Window][TreePanel]
|
[Window][TreePanel]
|
||||||
Pos=0,34
|
Pos=0,34
|
||||||
Size=486,1336
|
Size=486,804
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000001,0
|
DockId=0x00000001,0
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ DockId=0xA1672E74,1
|
|||||||
|
|
||||||
[Window][PropertiesPanel]
|
[Window][PropertiesPanel]
|
||||||
Pos=2002,34
|
Pos=2002,34
|
||||||
Size=558,1336
|
Size=558,804
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
DockId=0x00000003,0
|
DockId=0x00000003,0
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user