From c19a282e10f51ddd50d198b903f8fbd5a2238b62 Mon Sep 17 00:00:00 2001 From: chai Date: Mon, 4 Mar 2019 08:59:21 +0800 Subject: *misc --- Source/Asura.Engine/Application.cpp | 29 ++++++++++------ Source/Asura.Engine/Application.h | 33 ++++++++++++------ Source/Asura.Engine/FileSystem/DecodedData.cpp | 1 + Source/Asura.Engine/FileSystem/Reloadable.h | 24 +++++++++++++ ...26\207\346\234\254\346\226\207\346\241\243.txt" | 0 .../Asura.Engine/Graphics/Application.Graphics.cpp | 20 +++++++++++ Source/Asura.Engine/Graphics/Image.h | 3 +- Source/Asura.Engine/Graphics/ImageData.cpp | 6 ---- Source/Asura.Engine/Graphics/Shader.h | 3 +- Source/Asura.Engine/Window/Window.cpp | 39 ++++++++++++++++++++-- Source/Asura.Engine/Window/Window.h | 16 ++++++--- 11 files changed, 138 insertions(+), 36 deletions(-) create mode 100644 Source/Asura.Engine/FileSystem/Reloadable.h create mode 100644 "Source/Asura.Engine/FileSystem/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" create mode 100644 Source/Asura.Engine/Graphics/Application.Graphics.cpp (limited to 'Source/Asura.Engine') diff --git a/Source/Asura.Engine/Application.cpp b/Source/Asura.Engine/Application.cpp index ba5feaa..59f5aae 100644 --- a/Source/Asura.Engine/Application.cpp +++ b/Source/Asura.Engine/Application.cpp @@ -1,4 +1,6 @@ #include "Application.h" +#include "Sdl2/SDL.h" +#include "Exceptions/Exception.h" namespace AsuraEngine { @@ -13,18 +15,23 @@ namespace AsuraEngine } - bool InitGraphics(bool init) + bool Application::Application::InitSubModules(uint flag) { - if (!init) return true; - - } + // 初始化子模块 + #define TryInitSubModule(module_name, func_name) \ + if((flag&ASURA_MODULE_##module_name) && !Application::Init##func_name()) \ + throw Exception("Asura init submodule %s failed.", #module_name); + + TryInitSubModule(GRAPHICS, Graphics); + TryInitSubModule(AUDIO, Audio); + TryInitSubModule(FONT, Font); + TryInitSubModule(INPUT, Input); + TryInitSubModule(MATH, Math); + TryInitSubModule(PHYSICS, Physics); + TryInitSubModule(TIME, Time); + TryInitSubModule(WINDOW, Window); - bool Application::Init(int flag) - { - if (!InitGraphics(flag & ASURA_MODULE_GRAPHICS)) - { - - } + } -} +} \ No newline at end of file diff --git a/Source/Asura.Engine/Application.h b/Source/Asura.Engine/Application.h index 68db22b..431924a 100644 --- a/Source/Asura.Engine/Application.h +++ b/Source/Asura.Engine/Application.h @@ -11,18 +11,18 @@ namespace AsuraEngine /// enum SubModules { - ASURA_MODULE_NONE = 0x00000000, + ASURA_MODULE_NONE = 0X00000000U, ASURA_MODULE_GRAPHICS = 1 << 1, - ASURA_MODULE_AUDIO = 1 << 2, - ASURA_MODULE_FONT = 1 << 3, - ASURA_MODULE_INPUT = 1 << 4, - ASURA_MODULE_MATH = 1 << 5, - ASURA_MODULE_PHYSICS = 1 << 6, - ASURA_MODULE_TIME = 1 << 7, - ASURA_MODULE_WINDOW = 1 << 8, - - ASURA_MODULE_ALL = 0XFFFFFFFF + ASURA_MODULE_AUDIO = 1 << 2, + ASURA_MODULE_FONT = 1 << 3, + ASURA_MODULE_INPUT = 1 << 4, + ASURA_MODULE_MATH = 1 << 5, + ASURA_MODULE_PHYSICS = 1 << 6, + ASURA_MODULE_TIME = 1 << 7, + ASURA_MODULE_WINDOW = 1 << 8, + + ASURA_MODULE_ALL = 0XFFFFFFFFU }; /// @@ -39,10 +39,21 @@ namespace AsuraEngine /// /// 初始化进入前的子系统 /// - bool Init(int subsystems = ASURA_MODULE_ALL); + bool InitSubModules(uint flag = ASURA_MODULE_ALL); virtual void Run(); + private: + + bool InitGraphics(); + bool InitAudio(); + bool InitFont(); + bool InitInput(); + bool InitMath(); + bool InitPhysics(); + bool InitTime(); + bool InitWindow(); + }; } diff --git a/Source/Asura.Engine/FileSystem/DecodedData.cpp b/Source/Asura.Engine/FileSystem/DecodedData.cpp index 90726cf..125c652 100644 --- a/Source/Asura.Engine/FileSystem/DecodedData.cpp +++ b/Source/Asura.Engine/FileSystem/DecodedData.cpp @@ -1,4 +1,5 @@ #include "DecodedData.h" +#include "Exceptions/Exception.h" namespace AsuraEngine { diff --git a/Source/Asura.Engine/FileSystem/Reloadable.h b/Source/Asura.Engine/FileSystem/Reloadable.h new file mode 100644 index 0000000..e07b094 --- /dev/null +++ b/Source/Asura.Engine/FileSystem/Reloadable.h @@ -0,0 +1,24 @@ +#ifndef __ASURA_ENGINE_RELOADABLE_H__ +#define __ASURA_ENGINE_RELOADABLE_H__ + +#include "Object.h" + +namespace AsuraEngine +{ + namespace Filesystem + { + + class Reloadable : virtual public Object + { + public: + Reloadable(); + ~Reloadable(); + + virtual bool Load(); + + }; + + } +} + +#endif \ No newline at end of file diff --git "a/Source/Asura.Engine/FileSystem/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" "b/Source/Asura.Engine/FileSystem/\346\226\260\345\273\272\346\226\207\346\234\254\346\226\207\346\241\243.txt" new file mode 100644 index 0000000..e69de29 diff --git a/Source/Asura.Engine/Graphics/Application.Graphics.cpp b/Source/Asura.Engine/Graphics/Application.Graphics.cpp new file mode 100644 index 0000000..64b9e09 --- /dev/null +++ b/Source/Asura.Engine/Graphics/Application.Graphics.cpp @@ -0,0 +1,20 @@ +#include "Application.h" +#include "Sdl2/SDL.h" +#include "Exceptions/Exception.h" + +namespace AsuraEngine +{ + + /// + /// 初始化graphics模块 + /// + bool Application::InitGraphics() + { + + if (SDL_Init(SDL_INIT_VIDEO) < 0) + return false; + + } + + +} \ No newline at end of file diff --git a/Source/Asura.Engine/Graphics/Image.h b/Source/Asura.Engine/Graphics/Image.h index da881aa..7897f74 100644 --- a/Source/Asura.Engine/Graphics/Image.h +++ b/Source/Asura.Engine/Graphics/Image.h @@ -1,6 +1,7 @@ #ifndef __ASURA_ENGINE_IMAGE_H__ #define __ASURA_ENGINE_IMAGE_H__ +#include "FileSystem/Reloadable.h" #include "StringMap.hpp" #include "Manager.hpp" #include "Texture.h" @@ -19,7 +20,7 @@ namespace AsuraEngine /// Image是图片从内存中载入后,读取进游戏后保存的结果。一个Image在内存、显存中只会保存一份,不会产生副本。需要特征 /// 化的区别image,如锚点位置,缩放和旋转角度,使用sprite。是一个只读类。主要是考虑到editor和engine使用不同的封装。 /// - class Image final : public Drawable, public Scripting::Portable + class Image final : public Drawable, public Scripting::Portable, public Filesystem::Reloadable { public: diff --git a/Source/Asura.Engine/Graphics/ImageData.cpp b/Source/Asura.Engine/Graphics/ImageData.cpp index af448bd..002de67 100644 --- a/Source/Asura.Engine/Graphics/ImageData.cpp +++ b/Source/Asura.Engine/Graphics/ImageData.cpp @@ -15,12 +15,6 @@ namespace AsuraEngine new STBDecoder() // jpeg, tga, bmp }; - void ImageData::ReleaseAllDecoders() - { - for (ImageDecoder* decoder : ImageDecoders) - decoder->Release(); - } - ImageData::ImageData(const Filesystem::DataBuffer* buffer) : DecodedData(buffer) { diff --git a/Source/Asura.Engine/Graphics/Shader.h b/Source/Asura.Engine/Graphics/Shader.h index 831f5c3..7dbfb0d 100644 --- a/Source/Asura.Engine/Graphics/Shader.h +++ b/Source/Asura.Engine/Graphics/Shader.h @@ -4,6 +4,7 @@ #include #include +#include "FileSystem/Reloadable.h" #include "Scripting/Luax.hpp" #include "Math/Vector2.hpp" #include "Math/Vector3.hpp" @@ -25,7 +26,7 @@ namespace AsuraEngine /// 一个shader是一个在材质间共享的程序。Shader本身不保存uniforms和顶点数据,只提供设置uniforms和use着色器的方法。编辑 /// 器针对每个shader,会通过shader代码找到声明的uniforms变量,并暴露给framework的material设置。 /// - class Shader final : virtual public Object + class Shader final : virtual public Object, public Filesystem::Reloadable { public: diff --git a/Source/Asura.Engine/Window/Window.cpp b/Source/Asura.Engine/Window/Window.cpp index 5e800e0..6e9300f 100644 --- a/Source/Asura.Engine/Window/Window.cpp +++ b/Source/Asura.Engine/Window/Window.cpp @@ -5,9 +5,9 @@ namespace AsuraEngine namespace Graphics { - Window::Window() + Window::Window(WindowStyle style) { - + //mWindowHandle = SDL_CreateWindow(); } Window::~Window() @@ -15,5 +15,40 @@ namespace AsuraEngine } + SDL_Window* Window::GetSDLWindowHandle() + { + return mWindowHandle; + } + + void Window::SetPosition(int x, int y) + { + + } + + void Window::SetTitle(const std::string& title) + { + + } + + void Window::Show() + { + + } + + void Window::Hide() + { + + } + + void Window::SetWindowStyle(WindowStyle style) + { + + } + + void Window::SwapRenderBuffer() + { + + } + } } diff --git a/Source/Asura.Engine/Window/Window.h b/Source/Asura.Engine/Window/Window.h index 3456d75..71aaf0e 100644 --- a/Source/Asura.Engine/Window/Window.h +++ b/Source/Asura.Engine/Window/Window.h @@ -12,21 +12,21 @@ namespace AsuraEngine enum WindowStyle { - + WINDOW_STYLE_FULLSCREEN = 1 << 1, }; /// /// 窗口,支持多窗口。在编辑器下需要多个窗口支持,runner只需要一个窗口。 /// - class Window final : public RenderTarget + class Window : public RenderTarget { public: - Window(); + Window(WindowStyle style); ~Window(); - SDL_Window* GetSDLHandle(); + SDL_Window* GetSDLWindowHandle(); void SetSize(uint width, uint height); @@ -45,6 +45,14 @@ namespace AsuraEngine /// void SwapRenderBuffer(); + void Clear(const Color& col = Color::Black); + + void Clear(const Math::Recti& quad, const Color& col = Color::Black); + + void Draw(const Drawable* texture, const RenderState& state); + + void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state); + private: /// -- cgit v1.1-26-g67d0