From bad78945ceba425f6a80e3b8dca2414d592970eb Mon Sep 17 00:00:00 2001 From: chai Date: Fri, 2 Aug 2019 20:51:00 +0800 Subject: =?UTF-8?q?*=E4=BF=AE=E6=94=B9=E6=96=87=E4=BB=B6=E5=90=8D=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bin/win64/LuaxTest.exe | Bin 526848 -> 0 bytes Build/Asura.Editor/Asura.Editor.vcxproj | 78 +- Build/Asura.Editor/Asura.Editor.vcxproj.filters | 181 +- Build/Asura.Runner/Asura.Runner.vcxproj | 11 +- Build/Asura.Runner/Asura.Runner.vcxproj.filters | 17 +- Source/Asura.Editor/main.cpp | 8 +- bin/win64/01-window.exe | Bin 1462272 -> 0 bytes bin/win64/05-physfs.exe | Bin 1210880 -> 0 bytes bin/win64/05-physfs.exe.lastcodeanalysissucceeded | 0 bin/win64/Luax.lib.lastcodeanalysissucceeded | 0 bin/win64/LuaxTest.exe | Bin 526848 -> 0 bytes bin/win64/SDL2.dll | Bin 2491904 -> 0 bytes .../asura-lib-utils.lib.lastcodeanalysissucceeded | 0 bin/win64/bindingGen.exe | Bin 10240 -> 0 bytes bin/win64/bindingGen.exe.config | 6 - bin/win64/img.jpg | Bin 59348 -> 0 bytes bin/win64/img.png | Bin 442 -> 0 bytes bin/win64/physfs.txt | 1 - bin/win64/physfs2.txt | 4528 -------------------- bin/win64/shader.png | Bin 28025 -> 0 bytes build/Asura.Editor/Asura.Editor.vcxproj | 78 +- build/Asura.Editor/Asura.Editor.vcxproj.filters | 181 +- build/Asura.Runner/Asura.Runner.vcxproj | 11 +- build/Asura.Runner/Asura.Runner.vcxproj.filters | 17 +- build/external/Luax/Luax.vcxproj | 4 +- build/external/Luax/Luax.vcxproj.filters | 4 +- build/modules/asura-base/asura-base.vcxproj | 6 +- .../modules/asura-base/asura-base.vcxproj.filters | 2 +- build/modules/asura-box2d/asura-box2d.vcxproj | 48 +- .../asura-box2d/asura-box2d.vcxproj.filters | 100 +- build/modules/asura-core/asura-core.vcxproj | 198 +- .../modules/asura-core/asura-core.vcxproj.filters | 484 +-- build/modules/asura-fmod/asura-fmod.vcxproj | 8 +- .../modules/asura-fmod/asura-fmod.vcxproj.filters | 8 +- build/modules/asura-json/asura-json.vcxproj | 16 +- .../modules/asura-json/asura-json.vcxproj.filters | 22 +- build/modules/asura-log/asura-log.vcxproj.filters | 17 +- build/modules/asura-network/asura-network.vcxproj | 2 +- .../asura-network/asura-network.vcxproj.filters | 4 +- build/modules/asura-openal/asura-openal.vcxproj | 40 +- .../asura-openal/asura-openal.vcxproj.filters | 80 +- .../modules/asura-plot/asura-plot.vcxproj.filters | 2 +- .../asura-steam/asura-steam.vcxproj.filters | 2 +- build/modules/asura-utils/asura-utils.vcxproj | 151 +- .../asura-utils/asura-utils.vcxproj.filters | 322 +- build/modules/asura-xml/asura-xml.vcxproj.filters | 2 +- build/tools/bindingGen/obj/Debug/bindingGen.exe | Bin 10240 -> 10240 bytes source/Asura.Editor/Config.h | 0 source/Asura.Editor/Controls/GUIButton.cpp | 11 + source/Asura.Editor/Controls/GUIButton.h | 14 + source/Asura.Editor/Controls/GUIContent.cpp | 8 + source/Asura.Editor/Controls/GUIContent.h | 17 + source/Asura.Editor/Controls/GUILabel.cpp | 8 + source/Asura.Editor/Controls/GUILabel.h | 14 + source/Asura.Editor/Controls/GUIPanel.cpp | 6 + source/Asura.Editor/Controls/GUIPanel.h | 16 + source/Asura.Editor/Controls/GUISlider.cpp | 8 + source/Asura.Editor/Controls/GUISlider.h | 14 + source/Asura.Editor/Controls/GUIToggle.cpp | 1 + source/Asura.Editor/Controls/GUIToggle.h | 16 + source/Asura.Editor/Controls/TextUtil.cpp | 0 source/Asura.Editor/Controls/TextUtil.h | 37 + source/Asura.Editor/Core/GUIState.h | 27 + source/Asura.Editor/Editor.cpp | 5 + source/Asura.Editor/Editor.h | 37 + source/Asura.Editor/Editor/asset_view.lua | 0 source/Asura.Editor/Editor/compile.bat | 0 source/Asura.Editor/Editor/compile.sh | 0 source/Asura.Editor/Editor/idea.txt | 0 source/Asura.Editor/Editor/main.lua | 4 + source/Asura.Editor/Editor/scene_view.lua | 4 + source/Asura.Editor/Graphics/Brush.cpp | 0 source/Asura.Editor/Graphics/Brush.h | 20 + source/Asura.Editor/Graphics/DrawInfo.cpp | 0 source/Asura.Editor/Graphics/DrawInfo.h | 16 + source/Asura.Editor/Graphics/Drawer.cpp | 16 + source/Asura.Editor/Graphics/Drawer.h | 40 + source/Asura.Editor/Graphics/Pen.cpp | 0 source/Asura.Editor/Graphics/Pen.h | 7 + source/Asura.Editor/Graphics/Shader.h | 18 + source/Asura.Editor/Graphics/Style.cpp | 0 source/Asura.Editor/Graphics/Style.h | 15 + .../Asura.Editor/Graphics/shaders/image.shader.h | 35 + .../Asura.Editor/Graphics/shaders/polygon.shader.h | 29 + source/Asura.Editor/Layout/HorizontalLayout.cpp | 0 source/Asura.Editor/Layout/HorizontalLayout.h | 0 source/Asura.Editor/Layout/VerticalLayout.cpp | 0 source/Asura.Editor/Layout/VerticalLayout.h | 0 source/Asura.Editor/Main.cpp | 30 + source/Asura.Editor/System/ContainerWindow.cpp | 0 source/Asura.Editor/System/ContainerWindow.h | 62 + source/Asura.Editor/System/FileWatcher.cpp | 0 source/Asura.Editor/System/FileWatcher.h | 517 +++ source/Asura.Editor/System/MenuController.cpp | 0 source/Asura.Editor/System/MenuController.h | 15 + source/Asura.Editor/Type.h | 30 + source/Asura.Editor/controls/button.cpp | 8 - source/Asura.Editor/controls/button.h | 14 - source/Asura.Editor/controls/content.cpp | 8 - source/Asura.Editor/controls/content.h | 17 - source/Asura.Editor/controls/label.cpp | 8 - source/Asura.Editor/controls/label.h | 14 - source/Asura.Editor/controls/panel.cpp | 16 - source/Asura.Editor/controls/panel.h | 16 - source/Asura.Editor/controls/toggle.cpp | 8 - source/Asura.Editor/controls/toggle.h | 14 - source/Asura.Editor/core/gui_state.h | 17 - source/Asura.Editor/editor.h | 6 +- source/Asura.Editor/graphics/brush.h | 4 +- source/Asura.Editor/graphics/draw_info.cpp | 0 source/Asura.Editor/graphics/draw_info.h | 14 - source/Asura.Editor/graphics/drawer.cpp | 2 +- source/Asura.Editor/graphics/drawer.h | 10 +- source/Asura.Editor/graphics/pen.h | 17 +- source/Asura.Editor/graphics/shader.h | 4 +- .../Asura.Editor/graphics/shaders/image.shader.h | 2 +- .../Asura.Editor/graphics/shaders/polygon.shader.h | 2 +- source/Asura.Editor/graphics/slider.cpp | 0 source/Asura.Editor/graphics/slider.h | 14 - source/Asura.Editor/graphics/style.h | 8 +- source/Asura.Editor/layout/horizontal_layout.cpp | 0 source/Asura.Editor/layout/horizontal_layout.h | 0 source/Asura.Editor/layout/vertical_layout.cpp | 0 source/Asura.Editor/layout/vertical_layout.h | 0 source/Asura.Editor/main.cpp | 8 +- source/Asura.Editor/system/editor_window.cpp | 6 - source/Asura.Editor/system/editor_window.h | 62 - source/Asura.Editor/system/file_watcher.cpp | 0 source/Asura.Editor/system/file_watcher.h | 517 --- source/Asura.Editor/type.h | 4 +- source/external/Luax/luax.h | 4 +- source/external/Luax/luax_class.inc | 637 +++ source/external/Luax/luax_class.inl | 637 --- source/external/Luax/luax_state.inc | 180 + source/external/Luax/luax_state.inl | 180 - source/modules/asura-base/Config.h | 69 + source/modules/asura-box2d/Box2DModule.cpp | 0 source/modules/asura-box2d/Box2DModule.h | 19 + source/modules/asura-box2d/Physics/Body.h | 67 + source/modules/asura-box2d/Physics/ChainShape.h | 29 + source/modules/asura-box2d/Physics/CircleShape.h | 0 source/modules/asura-box2d/Physics/Contact.h | 0 source/modules/asura-box2d/Physics/DebugDraw.h | 9 + source/modules/asura-box2d/Physics/DistanceJoint.h | 0 source/modules/asura-box2d/Physics/EdgeShape.h | 0 source/modules/asura-box2d/Physics/Fixture.h | 0 source/modules/asura-box2d/Physics/FrictionJoint.h | 0 source/modules/asura-box2d/Physics/GearJoint.h | 0 source/modules/asura-box2d/Physics/Joint.h | 0 source/modules/asura-box2d/Physics/MotorJoint.h | 0 source/modules/asura-box2d/Physics/MouseJoint.h | 0 source/modules/asura-box2d/Physics/PolygonShape.h | 0 .../modules/asura-box2d/Physics/PrismaticJoint.h | 0 source/modules/asura-box2d/Physics/PulleyJoint.h | 0 source/modules/asura-box2d/Physics/RevoluteJoint.h | 0 source/modules/asura-box2d/Physics/RopeJoint.h | 0 source/modules/asura-box2d/Physics/Shape.h | 0 source/modules/asura-box2d/Physics/WeldJoint.h | 0 source/modules/asura-box2d/Physics/WheelJoint.h | 0 source/modules/asura-box2d/Physics/World.h | 19 + .../modules/asura-box2d/Physics/binding/_body.cpp | 171 + .../modules/asura-box2d/Physics/binding/_world.cpp | 21 + source/modules/asura-box2d/box2d_module.cpp | 0 source/modules/asura-box2d/box2d_module.h | 19 - .../modules/asura-box2d/physics/binding/_body.cpp | 2 +- .../modules/asura-box2d/physics/binding/_world.cpp | 2 +- source/modules/asura-box2d/physics/body.h | 2 +- source/modules/asura-box2d/physics/chain_shape.h | 32 - source/modules/asura-box2d/physics/circle_shape.h | 0 source/modules/asura-box2d/physics/debug_draw.h | 9 - .../modules/asura-box2d/physics/distance_joint.h | 0 source/modules/asura-box2d/physics/edge_shape.h | 0 .../modules/asura-box2d/physics/friction_joint.h | 0 source/modules/asura-box2d/physics/gear_joint.h | 0 source/modules/asura-box2d/physics/motor_joint.h | 0 source/modules/asura-box2d/physics/mouse_joint.h | 0 source/modules/asura-box2d/physics/polygon_shape.h | 0 .../modules/asura-box2d/physics/prismatic_joint.h | 0 source/modules/asura-box2d/physics/pulley_joint.h | 0 .../modules/asura-box2d/physics/revolute_joint.h | 0 source/modules/asura-box2d/physics/rope_joint.h | 0 source/modules/asura-box2d/physics/weld_joint.h | 0 source/modules/asura-box2d/physics/wheel_joint.h | 0 source/modules/asura-box2d/physics/world.h | 2 +- source/modules/asura-core/Application.cpp | 23 + source/modules/asura-core/Application.h | 81 + source/modules/asura-core/CoreConfig.h | 13 + source/modules/asura-core/CoreModule.cpp | 25 + source/modules/asura-core/CoreModule.h | 26 + source/modules/asura-core/Font/Glyph.cpp | 0 source/modules/asura-core/Font/Glyph.h | 0 source/modules/asura-core/Font/String.cpp | 376 ++ source/modules/asura-core/Font/String.hpp | 595 +++ source/modules/asura-core/Font/String.inc | 29 + source/modules/asura-core/Font/TTF.cpp | 0 source/modules/asura-core/Font/TTF.h | 17 + source/modules/asura-core/Font/Utf.hpp | 720 ++++ source/modules/asura-core/Font/Utf.inc | 752 ++++ source/modules/asura-core/Graphics/BlendMode.h | 17 + source/modules/asura-core/Graphics/Canvas.cpp | 49 + source/modules/asura-core/Graphics/Canvas.h | 73 + source/modules/asura-core/Graphics/Color.cpp | 58 + source/modules/asura-core/Graphics/Color.h | 75 + source/modules/asura-core/Graphics/Color32.cpp | 53 + source/modules/asura-core/Graphics/Color32.h | 58 + source/modules/asura-core/Graphics/ColorPalette.h | 0 source/modules/asura-core/Graphics/DrawInfo.cpp | 10 + source/modules/asura-core/Graphics/DrawInfo.h | 18 + source/modules/asura-core/Graphics/GPUBuffer.cpp | 151 + source/modules/asura-core/Graphics/GPUBuffer.h | 95 + source/modules/asura-core/Graphics/GfxDevice.cpp | 208 + source/modules/asura-core/Graphics/GfxDevice.h | 139 + source/modules/asura-core/Graphics/Image.cpp | 103 + source/modules/asura-core/Graphics/Image.h | 63 + source/modules/asura-core/Graphics/IndexBuffer.cpp | 17 + source/modules/asura-core/Graphics/IndexBuffer.h | 34 + source/modules/asura-core/Graphics/MatrixStack.cpp | 75 + source/modules/asura-core/Graphics/MatrixStack.h | 58 + source/modules/asura-core/Graphics/Mesh2D.cpp | 0 source/modules/asura-core/Graphics/Mesh2D.h | 52 + source/modules/asura-core/Graphics/Quad.cpp | 0 source/modules/asura-core/Graphics/Quad.h | 1 + source/modules/asura-core/Graphics/RenderState.h | 47 + .../modules/asura-core/Graphics/RenderTarget.cpp | 0 source/modules/asura-core/Graphics/RenderTarget.h | 52 + source/modules/asura-core/Graphics/Shader.cpp | 282 ++ source/modules/asura-core/Graphics/Shader.h | 117 + source/modules/asura-core/Graphics/Shape.cpp | 0 source/modules/asura-core/Graphics/Shape.h | 0 source/modules/asura-core/Graphics/SpriteBatch.cpp | 0 source/modules/asura-core/Graphics/SpriteBatch.h | 34 + source/modules/asura-core/Graphics/Texture.cpp | 47 + source/modules/asura-core/Graphics/Texture.h | 101 + .../modules/asura-core/Graphics/VertexBuffer.cpp | 16 + source/modules/asura-core/Graphics/VertexBuffer.h | 34 + .../asura-core/Graphics/binding/_canvas.cpp | 48 + .../modules/asura-core/Graphics/binding/_color.cpp | 130 + .../asura-core/Graphics/binding/_color32.cpp | 66 + .../asura-core/Graphics/binding/_gfx_device.cpp | 151 + .../asura-core/Graphics/binding/_gpu_buffer.cpp | 118 + .../modules/asura-core/Graphics/binding/_image.cpp | 71 + .../asura-core/Graphics/binding/_index_buffer.cpp | 31 + .../asura-core/Graphics/binding/_mesh2d.cpp | 20 + .../asura-core/Graphics/binding/_shader.cpp | 131 + .../asura-core/Graphics/binding/_sprite_batch.cpp | 20 + .../asura-core/Graphics/binding/_texture.cpp | 85 + .../asura-core/Graphics/binding/_vertex_buffer.cpp | 38 + source/modules/asura-core/Image/ImageData.cpp | 62 + source/modules/asura-core/Image/ImageData.h | 81 + .../modules/asura-core/Image/ImageDecodeTask.cpp | 17 + source/modules/asura-core/Image/ImageDecodeTask.h | 35 + source/modules/asura-core/Image/ImageDecoder.h | 33 + source/modules/asura-core/Image/PngDecoder.cpp | 17 + source/modules/asura-core/Image/PngDecoder.h | 25 + source/modules/asura-core/Image/StbDecoder.cpp | 73 + source/modules/asura-core/Image/StbDecoder.h | 26 + .../asura-core/Image/binding/_image_data.cpp | 108 + .../Image/binding/_image_decode_task.cpp | 19 + source/modules/asura-core/Input/Button.h | 31 + source/modules/asura-core/Input/ClipBoard.cpp | 0 source/modules/asura-core/Input/ClipBoard.h | 0 source/modules/asura-core/Input/InputDevice.cpp | 0 source/modules/asura-core/Input/InputDevice.h | 39 + source/modules/asura-core/Input/InputManager.cpp | 0 source/modules/asura-core/Input/InputManager.h | 24 + source/modules/asura-core/Input/JoystickState.h | 0 source/modules/asura-core/Input/KeyboardState.h | 37 + source/modules/asura-core/Input/Keys.h | 482 +++ source/modules/asura-core/Input/MouseState.h | 0 source/modules/asura-core/Mesh/Am2Handler.cpp | 34 + source/modules/asura-core/Mesh/Am2Handler.h | 30 + source/modules/asura-core/Mesh/Mesh2DData.cpp | 0 source/modules/asura-core/Mesh/Mesh2DData.h | 78 + source/modules/asura-core/Mesh/Mesh2DHandler.cpp | 0 source/modules/asura-core/Mesh/Mesh2DHandler.h | 32 + source/modules/asura-core/Mesh/ObjHandler.cpp | 0 source/modules/asura-core/Mesh/ObjHandler.h | 0 source/modules/asura-core/Profiler/GPUProfiler.cpp | 0 source/modules/asura-core/Profiler/GPUProfiler.h | 0 source/modules/asura-core/Profiler/Stats.cpp | 0 source/modules/asura-core/Profiler/Stats.h | 0 source/modules/asura-core/Threads/Channel.cpp | 0 source/modules/asura-core/Threads/Channel.h | 18 + source/modules/asura-core/Threads/ThreadEx.cpp | 20 + source/modules/asura-core/Threads/ThreadEx.h | 45 + source/modules/asura-core/Time/Timer.cpp | 0 source/modules/asura-core/Time/Timer.h | 0 source/modules/asura-core/Type.h | 11 + source/modules/asura-core/Window/Window.cpp | 104 + source/modules/asura-core/Window/Window.h | 138 + .../modules/asura-core/Window/WindowImplGlew.cpp | 0 source/modules/asura-core/Window/WindowImplGlew.h | 0 source/modules/asura-core/Window/WindowImplGlut.h | 0 source/modules/asura-core/Window/WindowImplSDL.cpp | 153 + source/modules/asura-core/Window/WindowImplSDL.h | 45 + .../modules/asura-core/Window/WinodwImplGlut.cpp | 0 .../modules/asura-core/Window/binding/_window.cpp | 179 + source/modules/asura-core/application.h | 14 +- source/modules/asura-core/core_config.h | 13 - source/modules/asura-core/core_module.cpp | 25 - source/modules/asura-core/core_module.h | 28 - source/modules/asura-core/font/string.hpp | 6 +- source/modules/asura-core/font/string.inl | 29 - source/modules/asura-core/font/ttf.h | 4 +- source/modules/asura-core/font/utf.hpp | 6 +- source/modules/asura-core/font/utf.inl | 752 ---- .../asura-core/graphics/binding/_canvas.cpp | 2 +- .../modules/asura-core/graphics/binding/_color.cpp | 2 +- .../asura-core/graphics/binding/_color32.cpp | 2 +- .../asura-core/graphics/binding/_gfx_device.cpp | 2 +- .../asura-core/graphics/binding/_gpu_buffer.cpp | 2 +- .../asura-core/graphics/binding/_index_buffer.cpp | 2 +- .../asura-core/graphics/binding/_sprite_batch.cpp | 2 +- .../asura-core/graphics/binding/_vertex_buffer.cpp | 2 +- source/modules/asura-core/graphics/blend_mode.h | 17 - source/modules/asura-core/graphics/canvas.h | 24 +- source/modules/asura-core/graphics/color.cpp | 4 +- source/modules/asura-core/graphics/color.h | 10 +- source/modules/asura-core/graphics/color32.cpp | 4 +- source/modules/asura-core/graphics/color32.h | 10 +- source/modules/asura-core/graphics/color_palette.h | 0 source/modules/asura-core/graphics/gfx_device.cpp | 208 - source/modules/asura-core/graphics/gfx_device.h | 139 - source/modules/asura-core/graphics/gpu_buffer.cpp | 151 - source/modules/asura-core/graphics/gpu_buffer.h | 95 - source/modules/asura-core/graphics/image.cpp | 10 +- source/modules/asura-core/graphics/image.h | 28 +- .../modules/asura-core/graphics/index_buffer.cpp | 17 - source/modules/asura-core/graphics/index_buffer.h | 34 - .../modules/asura-core/graphics/matrix_stack.cpp | 75 - source/modules/asura-core/graphics/matrix_stack.h | 58 - source/modules/asura-core/graphics/mesh2d.h | 16 +- source/modules/asura-core/graphics/render_state.h | 47 - .../modules/asura-core/graphics/render_target.cpp | 0 source/modules/asura-core/graphics/render_target.h | 52 - source/modules/asura-core/graphics/shader.cpp | 6 +- source/modules/asura-core/graphics/shader.h | 34 +- .../modules/asura-core/graphics/sprite_batch.cpp | 0 source/modules/asura-core/graphics/sprite_batch.h | 34 - source/modules/asura-core/graphics/texture.cpp | 2 +- source/modules/asura-core/graphics/texture.h | 14 +- .../modules/asura-core/graphics/vertex_buffer.cpp | 16 - source/modules/asura-core/graphics/vertex_buffer.h | 34 - .../asura-core/image/binding/_image_data.cpp | 6 +- .../image/binding/_image_decode_task.cpp | 15 +- source/modules/asura-core/image/image_data.cpp | 62 - source/modules/asura-core/image/image_data.h | 81 - .../modules/asura-core/image/image_decode_task.cpp | 17 - .../modules/asura-core/image/image_decode_task.h | 35 - source/modules/asura-core/image/image_decoder.h | 33 - source/modules/asura-core/image/png_decoder.cpp | 17 - source/modules/asura-core/image/png_decoder.h | 25 - source/modules/asura-core/image/stb_decoder.cpp | 73 - source/modules/asura-core/image/stb_decoder.h | 26 - source/modules/asura-core/input/button.h | 2 +- source/modules/asura-core/input/input_device.cpp | 0 source/modules/asura-core/input/input_device.h | 39 - source/modules/asura-core/input/input_manager.cpp | 0 source/modules/asura-core/input/input_manager.h | 24 - source/modules/asura-core/input/joystick_state.h | 0 source/modules/asura-core/input/keyboard_state.h | 37 - source/modules/asura-core/input/mouse_state.h | 0 source/modules/asura-core/mesh/am2_handler.cpp | 34 - source/modules/asura-core/mesh/am2_handler.h | 30 - source/modules/asura-core/mesh/mesh2d_data.cpp | 0 source/modules/asura-core/mesh/mesh2d_data.h | 78 - source/modules/asura-core/mesh/mesh2d_handler.cpp | 0 source/modules/asura-core/mesh/mesh2d_handler.h | 32 - source/modules/asura-core/mesh/obj_handler.cpp | 0 source/modules/asura-core/mesh/obj_handler.h | 0 .../modules/asura-core/profiler/gpu_profiler.cpp | 0 source/modules/asura-core/profiler/gpu_profiler.h | 0 source/modules/asura-core/threading/channel.cpp | 0 source/modules/asura-core/threading/channel.h | 18 - source/modules/asura-core/threading/thread_ex.cpp | 20 - source/modules/asura-core/threading/thread_ex.h | 45 - source/modules/asura-core/type.h | 4 +- .../modules/asura-core/window/binding/_window.cpp | 4 +- source/modules/asura-core/window/window.cpp | 8 +- source/modules/asura-core/window/window.h | 16 +- .../modules/asura-core/window/window_impl_glew.cpp | 0 .../modules/asura-core/window/window_impl_glew.h | 0 .../modules/asura-core/window/window_impl_glut.cpp | 0 .../modules/asura-core/window/window_impl_glut.h | 0 .../modules/asura-core/window/window_impl_sdl.cpp | 153 - source/modules/asura-core/window/window_impl_sdl.h | 45 - source/modules/asura-fmod/Audio/Source.h | 20 + source/modules/asura-fmod/FMODModule.h | 9 + source/modules/asura-fmod/fmod_module.h | 9 - source/modules/asura-json/Json/Json.cpp | 0 source/modules/asura-json/Json/Json.h | 14 + source/modules/asura-json/JsonModule.cpp | 0 source/modules/asura-json/JsonModule.h | 0 source/modules/asura-json/json_module.cpp | 0 source/modules/asura-json/json_module.h | 0 source/modules/asura-network/NetworkModule.h | 0 source/modules/asura-network/network_module.h | 0 source/modules/asura-openal/Audio/Audio.cpp | 0 source/modules/asura-openal/Audio/Audio.h | 0 .../modules/asura-openal/Audio/MPG123Decoder.cpp | 0 source/modules/asura-openal/Audio/MPG123Decoder.h | 0 source/modules/asura-openal/Audio/Sound.cpp | 0 source/modules/asura-openal/Audio/Sound.h | 31 + source/modules/asura-openal/Audio/SoundData.cpp | 0 source/modules/asura-openal/Audio/SoundData.h | 0 .../modules/asura-openal/Audio/SoundDecodeTask.cpp | 0 .../modules/asura-openal/Audio/SoundDecodeTask.h | 0 source/modules/asura-openal/Audio/SoundDecoder.cpp | 0 source/modules/asura-openal/Audio/SoundDecoder.h | 30 + source/modules/asura-openal/Audio/Source.cpp | 0 source/modules/asura-openal/Audio/Source.h | 0 .../modules/asura-openal/Audio/VorbisDecoder.cpp | 0 source/modules/asura-openal/Audio/VorbisDecoder.h | 0 .../modules/asura-openal/audio/mpg123_decoder.cpp | 0 source/modules/asura-openal/audio/mpg123_decoder.h | 0 source/modules/asura-openal/audio/sound.h | 2 +- source/modules/asura-openal/audio/sound_data.cpp | 0 source/modules/asura-openal/audio/sound_data.h | 0 .../asura-openal/audio/sound_decode_task.cpp | 0 .../modules/asura-openal/audio/sound_decode_task.h | 25 - .../modules/asura-openal/audio/sound_decoder.cpp | 29 - source/modules/asura-openal/audio/sound_decoder.h | 30 - .../modules/asura-openal/audio/vorbis_decoder.cpp | 0 source/modules/asura-openal/audio/vorbis_decoder.h | 0 source/modules/asura-utils/Classes.h | 9 + .../modules/asura-utils/Exceptions/Exception.cpp | 40 + source/modules/asura-utils/Exceptions/Exception.h | 30 + source/modules/asura-utils/IO/Compressor.cpp | 11 + source/modules/asura-utils/IO/Compressor.h | 28 + source/modules/asura-utils/IO/DataBuffer.cpp | 156 + source/modules/asura-utils/IO/DataBuffer.h | 87 + source/modules/asura-utils/IO/DecodedData.h | 41 + source/modules/asura-utils/IO/File.cpp | 294 ++ source/modules/asura-utils/IO/File.h | 146 + source/modules/asura-utils/IO/FileData.cpp | 59 + source/modules/asura-utils/IO/FileData.h | 69 + source/modules/asura-utils/IO/FileSystem.cpp | 198 + source/modules/asura-utils/IO/FileSystem.h | 112 + source/modules/asura-utils/IO/IOBatchTask.cpp | 0 source/modules/asura-utils/IO/IOBatchTask.h | 31 + source/modules/asura-utils/IO/IOTask.cpp | 61 + source/modules/asura-utils/IO/IOTask.h | 56 + source/modules/asura-utils/IO/Renewable.h | 29 + .../modules/asura-utils/IO/binding/_compressor.cpp | 0 .../asura-utils/IO/binding/_data_buffer.cpp | 132 + source/modules/asura-utils/IO/binding/_file.cpp | 223 + .../modules/asura-utils/IO/binding/_file_data.cpp | 60 + .../asura-utils/IO/binding/_file_system.cpp | 265 ++ source/modules/asura-utils/IO/binding/_io_task.cpp | 46 + source/modules/asura-utils/Manager.hpp | 14 + source/modules/asura-utils/Math/Curve.cpp | 0 source/modules/asura-utils/Math/Curve.h | 0 source/modules/asura-utils/Math/Functions.cpp | 0 source/modules/asura-utils/Math/Functions.h | 0 source/modules/asura-utils/Math/Matrix44.cpp | 217 + source/modules/asura-utils/Math/Matrix44.h | 98 + source/modules/asura-utils/Math/Quaternion.cpp | 0 source/modules/asura-utils/Math/Quaternion.h | 0 source/modules/asura-utils/Math/Rand/Rand.h | 89 + source/modules/asura-utils/Math/Rand/Random.h | 9 + source/modules/asura-utils/Math/RangedValue.cpp | 0 source/modules/asura-utils/Math/RangedValue.h | 0 source/modules/asura-utils/Math/Rect.hpp | 50 + source/modules/asura-utils/Math/Rect.inc | 28 + source/modules/asura-utils/Math/Transform.cpp | 0 source/modules/asura-utils/Math/Transform.h | 30 + source/modules/asura-utils/Math/Vector2.hpp | 72 + source/modules/asura-utils/Math/Vector2.inc | 114 + source/modules/asura-utils/Math/Vector3.hpp | 233 + source/modules/asura-utils/Math/Vector3.inc | 145 + source/modules/asura-utils/Math/Vector4.h | 234 + source/modules/asura-utils/Math/Vector4.inc | 152 + source/modules/asura-utils/Module.h | 32 + source/modules/asura-utils/Scripting/Portable.hpp | 31 + source/modules/asura-utils/Singleton.hpp | 59 + source/modules/asura-utils/StringMap.cpp | 0 source/modules/asura-utils/StringMap.hpp | 29 + source/modules/asura-utils/Threads/Conditional.cpp | 84 + source/modules/asura-utils/Threads/Conditional.h | 41 + source/modules/asura-utils/Threads/Coroutine.cpp | 15 + source/modules/asura-utils/Threads/Coroutine.h | 40 + source/modules/asura-utils/Threads/Mutex.cpp | 105 + source/modules/asura-utils/Threads/Mutex.h | 128 + source/modules/asura-utils/Threads/Semaphore.cpp | 99 + source/modules/asura-utils/Threads/Semaphore.h | 68 + source/modules/asura-utils/Threads/Task.cpp | 10 + source/modules/asura-utils/Threads/Task.h | 43 + source/modules/asura-utils/Threads/Thread.cpp | 287 ++ source/modules/asura-utils/Threads/Thread.h | 222 + .../asura-utils/Threads/ThreadImplPosix.cpp | 0 .../modules/asura-utils/Threads/ThreadImplPosix.h | 2 + .../modules/asura-utils/Threads/ThreadImplSDL.cpp | 0 source/modules/asura-utils/Threads/ThreadImplSDL.h | 0 .../modules/asura-utils/Threads/ThreadImplStd.cpp | 0 source/modules/asura-utils/Threads/ThreadImplStd.h | 41 + .../asura-utils/Threads/ThreadImplWin32.cpp | 77 + .../modules/asura-utils/Threads/ThreadImplWin32.h | 44 + source/modules/asura-utils/Threads/Threadable.h | 23 + .../asura-utils/Threads/binding/_coroutine.cpp | 38 + .../asura-utils/Threads/binding/_thread.cpp | 208 + source/modules/asura-utils/Type.h | 34 + source/modules/asura-utils/Utils.h | 6 + source/modules/asura-utils/UtilsConfig.h | 13 + source/modules/asura-utils/UtilsModule.cpp | 25 + source/modules/asura-utils/UtilsModule.h | 34 + source/modules/asura-utils/classes.h | 4 +- source/modules/asura-utils/exceptions/exception.h | 4 +- .../asura-utils/io/binding/_data_buffer.cpp | 2 +- .../modules/asura-utils/io/binding/_file_data.cpp | 2 +- .../asura-utils/io/binding/_file_system.cpp | 2 +- source/modules/asura-utils/io/binding/_io_task.cpp | 2 +- source/modules/asura-utils/io/compressor.cpp | 2 +- source/modules/asura-utils/io/compressor.h | 6 +- source/modules/asura-utils/io/data_buffer.cpp | 156 - source/modules/asura-utils/io/data_buffer.h | 87 - source/modules/asura-utils/io/decoded_data.h | 41 - source/modules/asura-utils/io/file.cpp | 4 +- source/modules/asura-utils/io/file.h | 10 +- source/modules/asura-utils/io/file_data.cpp | 59 - source/modules/asura-utils/io/file_data.h | 69 - source/modules/asura-utils/io/file_system.cpp | 198 - source/modules/asura-utils/io/file_system.h | 112 - source/modules/asura-utils/io/io_batch_task.cpp | 0 source/modules/asura-utils/io/io_batch_task.h | 31 - source/modules/asura-utils/io/io_task.cpp | 61 - source/modules/asura-utils/io/io_task.h | 56 - source/modules/asura-utils/io/renewable.h | 2 +- source/modules/asura-utils/manager.hpp | 4 +- source/modules/asura-utils/math/matrix44.cpp | 2 +- source/modules/asura-utils/math/matrix44.h | 6 +- source/modules/asura-utils/math/ranged_value.cpp | 0 source/modules/asura-utils/math/ranged_value.h | 0 source/modules/asura-utils/math/rect.hpp | 6 +- source/modules/asura-utils/math/rect.inl | 28 - source/modules/asura-utils/math/transform.h | 6 +- source/modules/asura-utils/math/vector2.hpp | 6 +- source/modules/asura-utils/math/vector2.inl | 114 - source/modules/asura-utils/math/vector3.hpp | 6 +- source/modules/asura-utils/math/vector3.inl | 145 - source/modules/asura-utils/math/vector4.h | 6 +- source/modules/asura-utils/math/vector4.inl | 152 - source/modules/asura-utils/module.h | 8 +- source/modules/asura-utils/scripting/portable.hpp | 18 +- source/modules/asura-utils/singleton.hpp | 8 +- source/modules/asura-utils/stringmap.hpp | 4 +- .../asura-utils/threading/binding/_coroutine.cpp | 38 - .../asura-utils/threading/binding/_thread.cpp | 208 - .../modules/asura-utils/threading/conditional.cpp | 84 - source/modules/asura-utils/threading/conditional.h | 41 - source/modules/asura-utils/threading/coroutine.cpp | 15 - source/modules/asura-utils/threading/coroutine.h | 40 - source/modules/asura-utils/threading/mutex.cpp | 105 - source/modules/asura-utils/threading/mutex.h | 128 - source/modules/asura-utils/threading/semaphore.cpp | 99 - source/modules/asura-utils/threading/semaphore.h | 68 - source/modules/asura-utils/threading/task.cpp | 10 - source/modules/asura-utils/threading/task.h | 43 - source/modules/asura-utils/threading/thread.cpp | 287 -- source/modules/asura-utils/threading/thread.h | 222 - .../asura-utils/threading/thread_impl_posix.cpp | 9 - .../asura-utils/threading/thread_impl_posix.h | 2 - .../asura-utils/threading/thread_impl_sdl.cpp | 0 .../asura-utils/threading/thread_impl_sdl.h | 0 .../asura-utils/threading/thread_impl_std.cpp | 0 .../asura-utils/threading/thread_impl_std.h | 41 - .../asura-utils/threading/thread_impl_win32.cpp | 77 - .../asura-utils/threading/thread_impl_win32.h | 44 - source/modules/asura-utils/threading/threadable.h | 23 - source/modules/asura-utils/type.h | 8 +- source/modules/asura-utils/utils.h | 6 +- source/modules/asura-utils/utils_config.h | 13 - source/modules/asura-utils/utils_module.cpp | 25 - source/modules/asura-utils/utils_module.h | 34 - source/tests/win32/01-window/02_multi_window.cpp | 2 +- source/tests/win32/01-window/03_sub_menu.cpp | 15 +- 575 files changed, 16941 insertions(+), 13256 deletions(-) delete mode 100644 Bin/win64/LuaxTest.exe delete mode 100644 bin/win64/01-window.exe delete mode 100644 bin/win64/05-physfs.exe delete mode 100644 bin/win64/05-physfs.exe.lastcodeanalysissucceeded delete mode 100644 bin/win64/Luax.lib.lastcodeanalysissucceeded delete mode 100644 bin/win64/LuaxTest.exe delete mode 100644 bin/win64/SDL2.dll delete mode 100644 bin/win64/asura-lib-utils.lib.lastcodeanalysissucceeded delete mode 100644 bin/win64/bindingGen.exe delete mode 100644 bin/win64/bindingGen.exe.config delete mode 100644 bin/win64/img.jpg delete mode 100644 bin/win64/img.png delete mode 100644 bin/win64/physfs.txt delete mode 100644 bin/win64/physfs2.txt delete mode 100644 bin/win64/shader.png create mode 100644 source/Asura.Editor/Config.h create mode 100644 source/Asura.Editor/Controls/GUIButton.cpp create mode 100644 source/Asura.Editor/Controls/GUIButton.h create mode 100644 source/Asura.Editor/Controls/GUIContent.cpp create mode 100644 source/Asura.Editor/Controls/GUIContent.h create mode 100644 source/Asura.Editor/Controls/GUILabel.cpp create mode 100644 source/Asura.Editor/Controls/GUILabel.h create mode 100644 source/Asura.Editor/Controls/GUIPanel.cpp create mode 100644 source/Asura.Editor/Controls/GUIPanel.h create mode 100644 source/Asura.Editor/Controls/GUISlider.cpp create mode 100644 source/Asura.Editor/Controls/GUISlider.h create mode 100644 source/Asura.Editor/Controls/GUIToggle.cpp create mode 100644 source/Asura.Editor/Controls/GUIToggle.h create mode 100644 source/Asura.Editor/Controls/TextUtil.cpp create mode 100644 source/Asura.Editor/Controls/TextUtil.h create mode 100644 source/Asura.Editor/Core/GUIState.h create mode 100644 source/Asura.Editor/Editor.cpp create mode 100644 source/Asura.Editor/Editor.h create mode 100644 source/Asura.Editor/Editor/asset_view.lua create mode 100644 source/Asura.Editor/Editor/compile.bat create mode 100644 source/Asura.Editor/Editor/compile.sh create mode 100644 source/Asura.Editor/Editor/idea.txt create mode 100644 source/Asura.Editor/Editor/main.lua create mode 100644 source/Asura.Editor/Editor/scene_view.lua create mode 100644 source/Asura.Editor/Graphics/Brush.cpp create mode 100644 source/Asura.Editor/Graphics/Brush.h create mode 100644 source/Asura.Editor/Graphics/DrawInfo.cpp create mode 100644 source/Asura.Editor/Graphics/DrawInfo.h create mode 100644 source/Asura.Editor/Graphics/Drawer.cpp create mode 100644 source/Asura.Editor/Graphics/Drawer.h create mode 100644 source/Asura.Editor/Graphics/Pen.cpp create mode 100644 source/Asura.Editor/Graphics/Pen.h create mode 100644 source/Asura.Editor/Graphics/Shader.h create mode 100644 source/Asura.Editor/Graphics/Style.cpp create mode 100644 source/Asura.Editor/Graphics/Style.h create mode 100644 source/Asura.Editor/Graphics/shaders/image.shader.h create mode 100644 source/Asura.Editor/Graphics/shaders/polygon.shader.h create mode 100644 source/Asura.Editor/Layout/HorizontalLayout.cpp create mode 100644 source/Asura.Editor/Layout/HorizontalLayout.h create mode 100644 source/Asura.Editor/Layout/VerticalLayout.cpp create mode 100644 source/Asura.Editor/Layout/VerticalLayout.h create mode 100644 source/Asura.Editor/Main.cpp create mode 100644 source/Asura.Editor/System/ContainerWindow.cpp create mode 100644 source/Asura.Editor/System/ContainerWindow.h create mode 100644 source/Asura.Editor/System/FileWatcher.cpp create mode 100644 source/Asura.Editor/System/FileWatcher.h create mode 100644 source/Asura.Editor/System/MenuController.cpp create mode 100644 source/Asura.Editor/System/MenuController.h create mode 100644 source/Asura.Editor/Type.h delete mode 100644 source/Asura.Editor/controls/button.cpp delete mode 100644 source/Asura.Editor/controls/button.h delete mode 100644 source/Asura.Editor/controls/content.cpp delete mode 100644 source/Asura.Editor/controls/content.h delete mode 100644 source/Asura.Editor/controls/label.cpp delete mode 100644 source/Asura.Editor/controls/label.h delete mode 100644 source/Asura.Editor/controls/panel.cpp delete mode 100644 source/Asura.Editor/controls/panel.h delete mode 100644 source/Asura.Editor/controls/toggle.cpp delete mode 100644 source/Asura.Editor/controls/toggle.h delete mode 100644 source/Asura.Editor/core/gui_state.h delete mode 100644 source/Asura.Editor/graphics/draw_info.cpp delete mode 100644 source/Asura.Editor/graphics/draw_info.h delete mode 100644 source/Asura.Editor/graphics/slider.cpp delete mode 100644 source/Asura.Editor/graphics/slider.h delete mode 100644 source/Asura.Editor/layout/horizontal_layout.cpp delete mode 100644 source/Asura.Editor/layout/horizontal_layout.h delete mode 100644 source/Asura.Editor/layout/vertical_layout.cpp delete mode 100644 source/Asura.Editor/layout/vertical_layout.h delete mode 100644 source/Asura.Editor/system/editor_window.cpp delete mode 100644 source/Asura.Editor/system/editor_window.h delete mode 100644 source/Asura.Editor/system/file_watcher.cpp delete mode 100644 source/Asura.Editor/system/file_watcher.h create mode 100644 source/external/Luax/luax_class.inc delete mode 100644 source/external/Luax/luax_class.inl create mode 100644 source/external/Luax/luax_state.inc delete mode 100644 source/external/Luax/luax_state.inl create mode 100644 source/modules/asura-base/Config.h create mode 100644 source/modules/asura-box2d/Box2DModule.cpp create mode 100644 source/modules/asura-box2d/Box2DModule.h create mode 100644 source/modules/asura-box2d/Physics/Body.h create mode 100644 source/modules/asura-box2d/Physics/ChainShape.h create mode 100644 source/modules/asura-box2d/Physics/CircleShape.h create mode 100644 source/modules/asura-box2d/Physics/Contact.h create mode 100644 source/modules/asura-box2d/Physics/DebugDraw.h create mode 100644 source/modules/asura-box2d/Physics/DistanceJoint.h create mode 100644 source/modules/asura-box2d/Physics/EdgeShape.h create mode 100644 source/modules/asura-box2d/Physics/Fixture.h create mode 100644 source/modules/asura-box2d/Physics/FrictionJoint.h create mode 100644 source/modules/asura-box2d/Physics/GearJoint.h create mode 100644 source/modules/asura-box2d/Physics/Joint.h create mode 100644 source/modules/asura-box2d/Physics/MotorJoint.h create mode 100644 source/modules/asura-box2d/Physics/MouseJoint.h create mode 100644 source/modules/asura-box2d/Physics/PolygonShape.h create mode 100644 source/modules/asura-box2d/Physics/PrismaticJoint.h create mode 100644 source/modules/asura-box2d/Physics/PulleyJoint.h create mode 100644 source/modules/asura-box2d/Physics/RevoluteJoint.h create mode 100644 source/modules/asura-box2d/Physics/RopeJoint.h create mode 100644 source/modules/asura-box2d/Physics/Shape.h create mode 100644 source/modules/asura-box2d/Physics/WeldJoint.h create mode 100644 source/modules/asura-box2d/Physics/WheelJoint.h create mode 100644 source/modules/asura-box2d/Physics/World.h create mode 100644 source/modules/asura-box2d/Physics/binding/_body.cpp create mode 100644 source/modules/asura-box2d/Physics/binding/_world.cpp delete mode 100644 source/modules/asura-box2d/box2d_module.cpp delete mode 100644 source/modules/asura-box2d/box2d_module.h delete mode 100644 source/modules/asura-box2d/physics/chain_shape.h delete mode 100644 source/modules/asura-box2d/physics/circle_shape.h delete mode 100644 source/modules/asura-box2d/physics/debug_draw.h delete mode 100644 source/modules/asura-box2d/physics/distance_joint.h delete mode 100644 source/modules/asura-box2d/physics/edge_shape.h delete mode 100644 source/modules/asura-box2d/physics/friction_joint.h delete mode 100644 source/modules/asura-box2d/physics/gear_joint.h delete mode 100644 source/modules/asura-box2d/physics/motor_joint.h delete mode 100644 source/modules/asura-box2d/physics/mouse_joint.h delete mode 100644 source/modules/asura-box2d/physics/polygon_shape.h delete mode 100644 source/modules/asura-box2d/physics/prismatic_joint.h delete mode 100644 source/modules/asura-box2d/physics/pulley_joint.h delete mode 100644 source/modules/asura-box2d/physics/revolute_joint.h delete mode 100644 source/modules/asura-box2d/physics/rope_joint.h delete mode 100644 source/modules/asura-box2d/physics/weld_joint.h delete mode 100644 source/modules/asura-box2d/physics/wheel_joint.h create mode 100644 source/modules/asura-core/Application.cpp create mode 100644 source/modules/asura-core/Application.h create mode 100644 source/modules/asura-core/CoreConfig.h create mode 100644 source/modules/asura-core/CoreModule.cpp create mode 100644 source/modules/asura-core/CoreModule.h create mode 100644 source/modules/asura-core/Font/Glyph.cpp create mode 100644 source/modules/asura-core/Font/Glyph.h create mode 100644 source/modules/asura-core/Font/String.cpp create mode 100644 source/modules/asura-core/Font/String.hpp create mode 100644 source/modules/asura-core/Font/String.inc create mode 100644 source/modules/asura-core/Font/TTF.cpp create mode 100644 source/modules/asura-core/Font/TTF.h create mode 100644 source/modules/asura-core/Font/Utf.hpp create mode 100644 source/modules/asura-core/Font/Utf.inc create mode 100644 source/modules/asura-core/Graphics/BlendMode.h create mode 100644 source/modules/asura-core/Graphics/Canvas.cpp create mode 100644 source/modules/asura-core/Graphics/Canvas.h create mode 100644 source/modules/asura-core/Graphics/Color.cpp create mode 100644 source/modules/asura-core/Graphics/Color.h create mode 100644 source/modules/asura-core/Graphics/Color32.cpp create mode 100644 source/modules/asura-core/Graphics/Color32.h create mode 100644 source/modules/asura-core/Graphics/ColorPalette.h create mode 100644 source/modules/asura-core/Graphics/DrawInfo.cpp create mode 100644 source/modules/asura-core/Graphics/DrawInfo.h create mode 100644 source/modules/asura-core/Graphics/GPUBuffer.cpp create mode 100644 source/modules/asura-core/Graphics/GPUBuffer.h create mode 100644 source/modules/asura-core/Graphics/GfxDevice.cpp create mode 100644 source/modules/asura-core/Graphics/GfxDevice.h create mode 100644 source/modules/asura-core/Graphics/Image.cpp create mode 100644 source/modules/asura-core/Graphics/Image.h create mode 100644 source/modules/asura-core/Graphics/IndexBuffer.cpp create mode 100644 source/modules/asura-core/Graphics/IndexBuffer.h create mode 100644 source/modules/asura-core/Graphics/MatrixStack.cpp create mode 100644 source/modules/asura-core/Graphics/MatrixStack.h create mode 100644 source/modules/asura-core/Graphics/Mesh2D.cpp create mode 100644 source/modules/asura-core/Graphics/Mesh2D.h create mode 100644 source/modules/asura-core/Graphics/Quad.cpp create mode 100644 source/modules/asura-core/Graphics/Quad.h create mode 100644 source/modules/asura-core/Graphics/RenderState.h create mode 100644 source/modules/asura-core/Graphics/RenderTarget.cpp create mode 100644 source/modules/asura-core/Graphics/RenderTarget.h create mode 100644 source/modules/asura-core/Graphics/Shader.cpp create mode 100644 source/modules/asura-core/Graphics/Shader.h create mode 100644 source/modules/asura-core/Graphics/Shape.cpp create mode 100644 source/modules/asura-core/Graphics/Shape.h create mode 100644 source/modules/asura-core/Graphics/SpriteBatch.cpp create mode 100644 source/modules/asura-core/Graphics/SpriteBatch.h create mode 100644 source/modules/asura-core/Graphics/Texture.cpp create mode 100644 source/modules/asura-core/Graphics/Texture.h create mode 100644 source/modules/asura-core/Graphics/VertexBuffer.cpp create mode 100644 source/modules/asura-core/Graphics/VertexBuffer.h create mode 100644 source/modules/asura-core/Graphics/binding/_canvas.cpp create mode 100644 source/modules/asura-core/Graphics/binding/_color.cpp create mode 100644 source/modules/asura-core/Graphics/binding/_color32.cpp create mode 100644 source/modules/asura-core/Graphics/binding/_gfx_device.cpp create mode 100644 source/modules/asura-core/Graphics/binding/_gpu_buffer.cpp create mode 100644 source/modules/asura-core/Graphics/binding/_image.cpp create mode 100644 source/modules/asura-core/Graphics/binding/_index_buffer.cpp create mode 100644 source/modules/asura-core/Graphics/binding/_mesh2d.cpp create mode 100644 source/modules/asura-core/Graphics/binding/_shader.cpp create mode 100644 source/modules/asura-core/Graphics/binding/_sprite_batch.cpp create mode 100644 source/modules/asura-core/Graphics/binding/_texture.cpp create mode 100644 source/modules/asura-core/Graphics/binding/_vertex_buffer.cpp create mode 100644 source/modules/asura-core/Image/ImageData.cpp create mode 100644 source/modules/asura-core/Image/ImageData.h create mode 100644 source/modules/asura-core/Image/ImageDecodeTask.cpp create mode 100644 source/modules/asura-core/Image/ImageDecodeTask.h create mode 100644 source/modules/asura-core/Image/ImageDecoder.h create mode 100644 source/modules/asura-core/Image/PngDecoder.cpp create mode 100644 source/modules/asura-core/Image/PngDecoder.h create mode 100644 source/modules/asura-core/Image/StbDecoder.cpp create mode 100644 source/modules/asura-core/Image/StbDecoder.h create mode 100644 source/modules/asura-core/Image/binding/_image_data.cpp create mode 100644 source/modules/asura-core/Image/binding/_image_decode_task.cpp create mode 100644 source/modules/asura-core/Input/Button.h create mode 100644 source/modules/asura-core/Input/ClipBoard.cpp create mode 100644 source/modules/asura-core/Input/ClipBoard.h create mode 100644 source/modules/asura-core/Input/InputDevice.cpp create mode 100644 source/modules/asura-core/Input/InputDevice.h create mode 100644 source/modules/asura-core/Input/InputManager.cpp create mode 100644 source/modules/asura-core/Input/InputManager.h create mode 100644 source/modules/asura-core/Input/JoystickState.h create mode 100644 source/modules/asura-core/Input/KeyboardState.h create mode 100644 source/modules/asura-core/Input/Keys.h create mode 100644 source/modules/asura-core/Input/MouseState.h create mode 100644 source/modules/asura-core/Mesh/Am2Handler.cpp create mode 100644 source/modules/asura-core/Mesh/Am2Handler.h create mode 100644 source/modules/asura-core/Mesh/Mesh2DData.cpp create mode 100644 source/modules/asura-core/Mesh/Mesh2DData.h create mode 100644 source/modules/asura-core/Mesh/Mesh2DHandler.cpp create mode 100644 source/modules/asura-core/Mesh/Mesh2DHandler.h create mode 100644 source/modules/asura-core/Mesh/ObjHandler.cpp create mode 100644 source/modules/asura-core/Mesh/ObjHandler.h create mode 100644 source/modules/asura-core/Profiler/GPUProfiler.cpp create mode 100644 source/modules/asura-core/Profiler/GPUProfiler.h create mode 100644 source/modules/asura-core/Profiler/Stats.cpp create mode 100644 source/modules/asura-core/Profiler/Stats.h create mode 100644 source/modules/asura-core/Threads/Channel.cpp create mode 100644 source/modules/asura-core/Threads/Channel.h create mode 100644 source/modules/asura-core/Threads/ThreadEx.cpp create mode 100644 source/modules/asura-core/Threads/ThreadEx.h create mode 100644 source/modules/asura-core/Time/Timer.cpp create mode 100644 source/modules/asura-core/Time/Timer.h create mode 100644 source/modules/asura-core/Type.h create mode 100644 source/modules/asura-core/Window/Window.cpp create mode 100644 source/modules/asura-core/Window/Window.h create mode 100644 source/modules/asura-core/Window/WindowImplGlew.cpp create mode 100644 source/modules/asura-core/Window/WindowImplGlew.h create mode 100644 source/modules/asura-core/Window/WindowImplGlut.h create mode 100644 source/modules/asura-core/Window/WindowImplSDL.cpp create mode 100644 source/modules/asura-core/Window/WindowImplSDL.h create mode 100644 source/modules/asura-core/Window/WinodwImplGlut.cpp create mode 100644 source/modules/asura-core/Window/binding/_window.cpp delete mode 100644 source/modules/asura-core/core_config.h delete mode 100644 source/modules/asura-core/core_module.cpp delete mode 100644 source/modules/asura-core/core_module.h delete mode 100644 source/modules/asura-core/font/string.inl delete mode 100644 source/modules/asura-core/font/utf.inl delete mode 100644 source/modules/asura-core/graphics/blend_mode.h delete mode 100644 source/modules/asura-core/graphics/color_palette.h delete mode 100644 source/modules/asura-core/graphics/gfx_device.cpp delete mode 100644 source/modules/asura-core/graphics/gfx_device.h delete mode 100644 source/modules/asura-core/graphics/gpu_buffer.cpp delete mode 100644 source/modules/asura-core/graphics/gpu_buffer.h delete mode 100644 source/modules/asura-core/graphics/index_buffer.cpp delete mode 100644 source/modules/asura-core/graphics/index_buffer.h delete mode 100644 source/modules/asura-core/graphics/matrix_stack.cpp delete mode 100644 source/modules/asura-core/graphics/matrix_stack.h delete mode 100644 source/modules/asura-core/graphics/render_state.h delete mode 100644 source/modules/asura-core/graphics/render_target.cpp delete mode 100644 source/modules/asura-core/graphics/render_target.h delete mode 100644 source/modules/asura-core/graphics/sprite_batch.cpp delete mode 100644 source/modules/asura-core/graphics/sprite_batch.h delete mode 100644 source/modules/asura-core/graphics/vertex_buffer.cpp delete mode 100644 source/modules/asura-core/graphics/vertex_buffer.h delete mode 100644 source/modules/asura-core/image/image_data.cpp delete mode 100644 source/modules/asura-core/image/image_data.h delete mode 100644 source/modules/asura-core/image/image_decode_task.cpp delete mode 100644 source/modules/asura-core/image/image_decode_task.h delete mode 100644 source/modules/asura-core/image/image_decoder.h delete mode 100644 source/modules/asura-core/image/png_decoder.cpp delete mode 100644 source/modules/asura-core/image/png_decoder.h delete mode 100644 source/modules/asura-core/image/stb_decoder.cpp delete mode 100644 source/modules/asura-core/image/stb_decoder.h delete mode 100644 source/modules/asura-core/input/input_device.cpp delete mode 100644 source/modules/asura-core/input/input_device.h delete mode 100644 source/modules/asura-core/input/input_manager.cpp delete mode 100644 source/modules/asura-core/input/input_manager.h delete mode 100644 source/modules/asura-core/input/joystick_state.h delete mode 100644 source/modules/asura-core/input/keyboard_state.h delete mode 100644 source/modules/asura-core/input/mouse_state.h delete mode 100644 source/modules/asura-core/mesh/am2_handler.cpp delete mode 100644 source/modules/asura-core/mesh/am2_handler.h delete mode 100644 source/modules/asura-core/mesh/mesh2d_data.cpp delete mode 100644 source/modules/asura-core/mesh/mesh2d_data.h delete mode 100644 source/modules/asura-core/mesh/mesh2d_handler.cpp delete mode 100644 source/modules/asura-core/mesh/mesh2d_handler.h delete mode 100644 source/modules/asura-core/mesh/obj_handler.cpp delete mode 100644 source/modules/asura-core/mesh/obj_handler.h delete mode 100644 source/modules/asura-core/profiler/gpu_profiler.cpp delete mode 100644 source/modules/asura-core/profiler/gpu_profiler.h delete mode 100644 source/modules/asura-core/threading/channel.cpp delete mode 100644 source/modules/asura-core/threading/channel.h delete mode 100644 source/modules/asura-core/threading/thread_ex.cpp delete mode 100644 source/modules/asura-core/threading/thread_ex.h delete mode 100644 source/modules/asura-core/window/window_impl_glew.cpp delete mode 100644 source/modules/asura-core/window/window_impl_glew.h delete mode 100644 source/modules/asura-core/window/window_impl_glut.cpp delete mode 100644 source/modules/asura-core/window/window_impl_glut.h delete mode 100644 source/modules/asura-core/window/window_impl_sdl.cpp delete mode 100644 source/modules/asura-core/window/window_impl_sdl.h create mode 100644 source/modules/asura-fmod/Audio/Source.h create mode 100644 source/modules/asura-fmod/FMODModule.h delete mode 100644 source/modules/asura-fmod/fmod_module.h create mode 100644 source/modules/asura-json/Json/Json.cpp create mode 100644 source/modules/asura-json/Json/Json.h create mode 100644 source/modules/asura-json/JsonModule.cpp create mode 100644 source/modules/asura-json/JsonModule.h delete mode 100644 source/modules/asura-json/json_module.cpp delete mode 100644 source/modules/asura-json/json_module.h create mode 100644 source/modules/asura-network/NetworkModule.h delete mode 100644 source/modules/asura-network/network_module.h create mode 100644 source/modules/asura-openal/Audio/Audio.cpp create mode 100644 source/modules/asura-openal/Audio/Audio.h create mode 100644 source/modules/asura-openal/Audio/MPG123Decoder.cpp create mode 100644 source/modules/asura-openal/Audio/MPG123Decoder.h create mode 100644 source/modules/asura-openal/Audio/Sound.cpp create mode 100644 source/modules/asura-openal/Audio/Sound.h create mode 100644 source/modules/asura-openal/Audio/SoundData.cpp create mode 100644 source/modules/asura-openal/Audio/SoundData.h create mode 100644 source/modules/asura-openal/Audio/SoundDecodeTask.cpp create mode 100644 source/modules/asura-openal/Audio/SoundDecodeTask.h create mode 100644 source/modules/asura-openal/Audio/SoundDecoder.cpp create mode 100644 source/modules/asura-openal/Audio/SoundDecoder.h create mode 100644 source/modules/asura-openal/Audio/Source.cpp create mode 100644 source/modules/asura-openal/Audio/Source.h create mode 100644 source/modules/asura-openal/Audio/VorbisDecoder.cpp create mode 100644 source/modules/asura-openal/Audio/VorbisDecoder.h delete mode 100644 source/modules/asura-openal/audio/mpg123_decoder.cpp delete mode 100644 source/modules/asura-openal/audio/mpg123_decoder.h delete mode 100644 source/modules/asura-openal/audio/sound_data.cpp delete mode 100644 source/modules/asura-openal/audio/sound_data.h delete mode 100644 source/modules/asura-openal/audio/sound_decode_task.cpp delete mode 100644 source/modules/asura-openal/audio/sound_decode_task.h delete mode 100644 source/modules/asura-openal/audio/sound_decoder.cpp delete mode 100644 source/modules/asura-openal/audio/sound_decoder.h delete mode 100644 source/modules/asura-openal/audio/vorbis_decoder.cpp delete mode 100644 source/modules/asura-openal/audio/vorbis_decoder.h create mode 100644 source/modules/asura-utils/Classes.h create mode 100644 source/modules/asura-utils/Exceptions/Exception.cpp create mode 100644 source/modules/asura-utils/Exceptions/Exception.h create mode 100644 source/modules/asura-utils/IO/Compressor.cpp create mode 100644 source/modules/asura-utils/IO/Compressor.h create mode 100644 source/modules/asura-utils/IO/DataBuffer.cpp create mode 100644 source/modules/asura-utils/IO/DataBuffer.h create mode 100644 source/modules/asura-utils/IO/DecodedData.h create mode 100644 source/modules/asura-utils/IO/File.cpp create mode 100644 source/modules/asura-utils/IO/File.h create mode 100644 source/modules/asura-utils/IO/FileData.cpp create mode 100644 source/modules/asura-utils/IO/FileData.h create mode 100644 source/modules/asura-utils/IO/FileSystem.cpp create mode 100644 source/modules/asura-utils/IO/FileSystem.h create mode 100644 source/modules/asura-utils/IO/IOBatchTask.cpp create mode 100644 source/modules/asura-utils/IO/IOBatchTask.h create mode 100644 source/modules/asura-utils/IO/IOTask.cpp create mode 100644 source/modules/asura-utils/IO/IOTask.h create mode 100644 source/modules/asura-utils/IO/Renewable.h create mode 100644 source/modules/asura-utils/IO/binding/_compressor.cpp create mode 100644 source/modules/asura-utils/IO/binding/_data_buffer.cpp create mode 100644 source/modules/asura-utils/IO/binding/_file.cpp create mode 100644 source/modules/asura-utils/IO/binding/_file_data.cpp create mode 100644 source/modules/asura-utils/IO/binding/_file_system.cpp create mode 100644 source/modules/asura-utils/IO/binding/_io_task.cpp create mode 100644 source/modules/asura-utils/Manager.hpp create mode 100644 source/modules/asura-utils/Math/Curve.cpp create mode 100644 source/modules/asura-utils/Math/Curve.h create mode 100644 source/modules/asura-utils/Math/Functions.cpp create mode 100644 source/modules/asura-utils/Math/Functions.h create mode 100644 source/modules/asura-utils/Math/Matrix44.cpp create mode 100644 source/modules/asura-utils/Math/Matrix44.h create mode 100644 source/modules/asura-utils/Math/Quaternion.cpp create mode 100644 source/modules/asura-utils/Math/Quaternion.h create mode 100644 source/modules/asura-utils/Math/Rand/Rand.h create mode 100644 source/modules/asura-utils/Math/Rand/Random.h create mode 100644 source/modules/asura-utils/Math/RangedValue.cpp create mode 100644 source/modules/asura-utils/Math/RangedValue.h create mode 100644 source/modules/asura-utils/Math/Rect.hpp create mode 100644 source/modules/asura-utils/Math/Rect.inc create mode 100644 source/modules/asura-utils/Math/Transform.cpp create mode 100644 source/modules/asura-utils/Math/Transform.h create mode 100644 source/modules/asura-utils/Math/Vector2.hpp create mode 100644 source/modules/asura-utils/Math/Vector2.inc create mode 100644 source/modules/asura-utils/Math/Vector3.hpp create mode 100644 source/modules/asura-utils/Math/Vector3.inc create mode 100644 source/modules/asura-utils/Math/Vector4.h create mode 100644 source/modules/asura-utils/Math/Vector4.inc create mode 100644 source/modules/asura-utils/Module.h create mode 100644 source/modules/asura-utils/Scripting/Portable.hpp create mode 100644 source/modules/asura-utils/Singleton.hpp create mode 100644 source/modules/asura-utils/StringMap.cpp create mode 100644 source/modules/asura-utils/StringMap.hpp create mode 100644 source/modules/asura-utils/Threads/Conditional.cpp create mode 100644 source/modules/asura-utils/Threads/Conditional.h create mode 100644 source/modules/asura-utils/Threads/Coroutine.cpp create mode 100644 source/modules/asura-utils/Threads/Coroutine.h create mode 100644 source/modules/asura-utils/Threads/Mutex.cpp create mode 100644 source/modules/asura-utils/Threads/Mutex.h create mode 100644 source/modules/asura-utils/Threads/Semaphore.cpp create mode 100644 source/modules/asura-utils/Threads/Semaphore.h create mode 100644 source/modules/asura-utils/Threads/Task.cpp create mode 100644 source/modules/asura-utils/Threads/Task.h create mode 100644 source/modules/asura-utils/Threads/Thread.cpp create mode 100644 source/modules/asura-utils/Threads/Thread.h create mode 100644 source/modules/asura-utils/Threads/ThreadImplPosix.cpp create mode 100644 source/modules/asura-utils/Threads/ThreadImplPosix.h create mode 100644 source/modules/asura-utils/Threads/ThreadImplSDL.cpp create mode 100644 source/modules/asura-utils/Threads/ThreadImplSDL.h create mode 100644 source/modules/asura-utils/Threads/ThreadImplStd.cpp create mode 100644 source/modules/asura-utils/Threads/ThreadImplStd.h create mode 100644 source/modules/asura-utils/Threads/ThreadImplWin32.cpp create mode 100644 source/modules/asura-utils/Threads/ThreadImplWin32.h create mode 100644 source/modules/asura-utils/Threads/Threadable.h create mode 100644 source/modules/asura-utils/Threads/binding/_coroutine.cpp create mode 100644 source/modules/asura-utils/Threads/binding/_thread.cpp create mode 100644 source/modules/asura-utils/Type.h create mode 100644 source/modules/asura-utils/Utils.h create mode 100644 source/modules/asura-utils/UtilsConfig.h create mode 100644 source/modules/asura-utils/UtilsModule.cpp create mode 100644 source/modules/asura-utils/UtilsModule.h delete mode 100644 source/modules/asura-utils/io/data_buffer.cpp delete mode 100644 source/modules/asura-utils/io/data_buffer.h delete mode 100644 source/modules/asura-utils/io/decoded_data.h delete mode 100644 source/modules/asura-utils/io/file_data.cpp delete mode 100644 source/modules/asura-utils/io/file_data.h delete mode 100644 source/modules/asura-utils/io/file_system.cpp delete mode 100644 source/modules/asura-utils/io/file_system.h delete mode 100644 source/modules/asura-utils/io/io_batch_task.cpp delete mode 100644 source/modules/asura-utils/io/io_batch_task.h delete mode 100644 source/modules/asura-utils/io/io_task.cpp delete mode 100644 source/modules/asura-utils/io/io_task.h delete mode 100644 source/modules/asura-utils/math/ranged_value.cpp delete mode 100644 source/modules/asura-utils/math/ranged_value.h delete mode 100644 source/modules/asura-utils/math/rect.inl delete mode 100644 source/modules/asura-utils/math/vector2.inl delete mode 100644 source/modules/asura-utils/math/vector3.inl delete mode 100644 source/modules/asura-utils/math/vector4.inl delete mode 100644 source/modules/asura-utils/threading/binding/_coroutine.cpp delete mode 100644 source/modules/asura-utils/threading/binding/_thread.cpp delete mode 100644 source/modules/asura-utils/threading/conditional.cpp delete mode 100644 source/modules/asura-utils/threading/conditional.h delete mode 100644 source/modules/asura-utils/threading/coroutine.cpp delete mode 100644 source/modules/asura-utils/threading/coroutine.h delete mode 100644 source/modules/asura-utils/threading/mutex.cpp delete mode 100644 source/modules/asura-utils/threading/mutex.h delete mode 100644 source/modules/asura-utils/threading/semaphore.cpp delete mode 100644 source/modules/asura-utils/threading/semaphore.h delete mode 100644 source/modules/asura-utils/threading/task.cpp delete mode 100644 source/modules/asura-utils/threading/task.h delete mode 100644 source/modules/asura-utils/threading/thread.cpp delete mode 100644 source/modules/asura-utils/threading/thread.h delete mode 100644 source/modules/asura-utils/threading/thread_impl_posix.cpp delete mode 100644 source/modules/asura-utils/threading/thread_impl_posix.h delete mode 100644 source/modules/asura-utils/threading/thread_impl_sdl.cpp delete mode 100644 source/modules/asura-utils/threading/thread_impl_sdl.h delete mode 100644 source/modules/asura-utils/threading/thread_impl_std.cpp delete mode 100644 source/modules/asura-utils/threading/thread_impl_std.h delete mode 100644 source/modules/asura-utils/threading/thread_impl_win32.cpp delete mode 100644 source/modules/asura-utils/threading/thread_impl_win32.h delete mode 100644 source/modules/asura-utils/threading/threadable.h delete mode 100644 source/modules/asura-utils/utils_config.h delete mode 100644 source/modules/asura-utils/utils_module.cpp delete mode 100644 source/modules/asura-utils/utils_module.h diff --git a/Bin/win64/LuaxTest.exe b/Bin/win64/LuaxTest.exe deleted file mode 100644 index 3acc2da..0000000 Binary files a/Bin/win64/LuaxTest.exe and /dev/null differ diff --git a/Build/Asura.Editor/Asura.Editor.vcxproj b/Build/Asura.Editor/Asura.Editor.vcxproj index 72dc736..b2168db 100644 --- a/Build/Asura.Editor/Asura.Editor.vcxproj +++ b/Build/Asura.Editor/Asura.Editor.vcxproj @@ -117,47 +117,51 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - + + + + + + + diff --git a/Build/Asura.Editor/Asura.Editor.vcxproj.filters b/Build/Asura.Editor/Asura.Editor.vcxproj.filters index 0e979a4..a535cb8 100644 --- a/Build/Asura.Editor/Asura.Editor.vcxproj.filters +++ b/Build/Asura.Editor/Asura.Editor.vcxproj.filters @@ -1,134 +1,149 @@ 锘 - - {7654ef3d-54c4-490f-bb24-e6a67bd63e1e} + + {a4345092-d09c-424c-8d7c-c076914fb6a2} - + {f67906bd-4f7c-4ac6-bca1-019617435a8b} - - {48600309-cddd-49cd-b939-7a19a2b1eaa3} - - + {4be8ce5c-0921-4341-a976-92d31aa84c8c} - + {b4c26f9c-9f4e-4332-a6e2-33456b4abecb} - - {a236e36b-9b74-48a2-a4c9-f70dbb321f14} + + {7654ef3d-54c4-490f-bb24-e6a67bd63e1e} + + + {48600309-cddd-49cd-b939-7a19a2b1eaa3} + + + {1e378398-d7f0-4616-a986-b6a86faeaa8c} - - layout + + Controls + + + Controls - - layout + + Controls - - - - system + + Controls - - graphics + + Controls - - graphics + + Graphics - - graphics + + Graphics - - graphics + + Graphics - - system + + Graphics - - graphics + + Graphics - - controls + + Layout - - controls + + Layout - - controls + + System - - controls + + + + Controls - - controls + + System - - controls + + System + + + Controls - - layout + + Graphics\shaders - - layout + + Graphics\shaders - - - system + + Controls - - - - graphics + + Controls - - graphics\shaders + + Controls - - graphics + + Controls - - graphics + + Controls - - graphics + + Core - - graphics + + Graphics - - graphics\shaders + + Graphics + + + Graphics + + + Graphics - - system + + Graphics - - core + + Graphics - - graphics + + Layout - - controls + + Layout - - controls + + System - - controls + + + + + Controls - - controls + + System - - controls + + System - - controls + + Controls \ No newline at end of file diff --git a/Build/Asura.Runner/Asura.Runner.vcxproj b/Build/Asura.Runner/Asura.Runner.vcxproj index ecf025b..0c18dc5 100644 --- a/Build/Asura.Runner/Asura.Runner.vcxproj +++ b/Build/Asura.Runner/Asura.Runner.vcxproj @@ -18,13 +18,6 @@ x64 - - - - - - - 15.0 {E21A839A-C7C6-4B83-89FB-C921AEBEA9CD} @@ -83,7 +76,6 @@ Disabled true true - $(SolutionDir)..\source\external;$(SolutionDir)..\source\modules;%(AdditionalIncludeDirectories) @@ -116,13 +108,14 @@ true true true - $(SolutionDir)..\source\external;$(SolutionDir)..\source\modules;%(AdditionalIncludeDirectories) true true + + diff --git a/Build/Asura.Runner/Asura.Runner.vcxproj.filters b/Build/Asura.Runner/Asura.Runner.vcxproj.filters index 1819f86..3c6f4fd 100644 --- a/Build/Asura.Runner/Asura.Runner.vcxproj.filters +++ b/Build/Asura.Runner/Asura.Runner.vcxproj.filters @@ -1,10 +1,17 @@ 锘 - - - - - + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + \ No newline at end of file diff --git a/Source/Asura.Editor/main.cpp b/Source/Asura.Editor/main.cpp index ed055cf..207474b 100644 --- a/Source/Asura.Editor/main.cpp +++ b/Source/Asura.Editor/main.cpp @@ -9,13 +9,13 @@ * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * - * 1. The origin of this software must not be misrepresented; you must not + * 1. The origin of this software m_ust not be m_isrepresented; you m_ust not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. + * 2. Altered source versions m_ust be plainly m_arked as such, and m_ust not be + * m_isrepresented as being the original software. + * 3. This notice m_ay not be removed or altered from any source distribution. **/ /// diff --git a/bin/win64/01-window.exe b/bin/win64/01-window.exe deleted file mode 100644 index f3f2e54..0000000 Binary files a/bin/win64/01-window.exe and /dev/null differ diff --git a/bin/win64/05-physfs.exe b/bin/win64/05-physfs.exe deleted file mode 100644 index e325343..0000000 Binary files a/bin/win64/05-physfs.exe and /dev/null differ diff --git a/bin/win64/05-physfs.exe.lastcodeanalysissucceeded b/bin/win64/05-physfs.exe.lastcodeanalysissucceeded deleted file mode 100644 index e69de29..0000000 diff --git a/bin/win64/Luax.lib.lastcodeanalysissucceeded b/bin/win64/Luax.lib.lastcodeanalysissucceeded deleted file mode 100644 index e69de29..0000000 diff --git a/bin/win64/LuaxTest.exe b/bin/win64/LuaxTest.exe deleted file mode 100644 index 3acc2da..0000000 Binary files a/bin/win64/LuaxTest.exe and /dev/null differ diff --git a/bin/win64/SDL2.dll b/bin/win64/SDL2.dll deleted file mode 100644 index becc4ba..0000000 Binary files a/bin/win64/SDL2.dll and /dev/null differ diff --git a/bin/win64/asura-lib-utils.lib.lastcodeanalysissucceeded b/bin/win64/asura-lib-utils.lib.lastcodeanalysissucceeded deleted file mode 100644 index e69de29..0000000 diff --git a/bin/win64/bindingGen.exe b/bin/win64/bindingGen.exe deleted file mode 100644 index 016c299..0000000 Binary files a/bin/win64/bindingGen.exe and /dev/null differ diff --git a/bin/win64/bindingGen.exe.config b/bin/win64/bindingGen.exe.config deleted file mode 100644 index 731f6de..0000000 --- a/bin/win64/bindingGen.exe.config +++ /dev/null @@ -1,6 +0,0 @@ -锘 - - - - - \ No newline at end of file diff --git a/bin/win64/img.jpg b/bin/win64/img.jpg deleted file mode 100644 index 8987cfe..0000000 Binary files a/bin/win64/img.jpg and /dev/null differ diff --git a/bin/win64/img.png b/bin/win64/img.png deleted file mode 100644 index 0d11f85..0000000 Binary files a/bin/win64/img.png and /dev/null differ diff --git a/bin/win64/physfs.txt b/bin/win64/physfs.txt deleted file mode 100644 index 00530bc..0000000 --- a/bin/win64/physfs.txt +++ /dev/null @@ -1 +0,0 @@ -hello, world你好 \ No newline at end of file diff --git a/bin/win64/physfs2.txt b/bin/win64/physfs2.txt deleted file mode 100644 index c0f0d31..0000000 --- a/bin/win64/physfs2.txt +++ /dev/null @@ -1,4528 +0,0 @@ -// This file has been modified from Ken Silverman's original release - -#define NOSOUND - -/*************************************************************************************************** -WINMAIN.CPP & SYSMAIN.H - -Windows layer code written by Ken Silverman (http://advsys.net/ken) (1997-2005) -Additional modifications by Tom Dobrowolski (http://ged.ax.pl/~tomkh) -You may use this code for non-commercial purposes as long as credit is maintained. -***************************************************************************************************/ - - //To compile, link with ddraw.lib, dinput.lib AND dxguid.lib. Be sure ddraw.h and dinput.h - //are in include path - -#include "StdAfx.h" -#include "msvc.h" -#include "Engine/Minidump.h" -#define WIN32_LEAN_AND_MEAN -#include - -#ifndef NODRAW -#define DIRECTDRAW_VERSION 0x0700 -#include "ddraw.h" -#endif -#ifndef NOINPUT -#define DIRECTINPUT_VERSION 0x0800 -#include "dinput.h" -#endif -#ifndef NOSOUND -#define DIRECTSOUND_VERSION 0x0900 -#include //dsound.h requires this when using LEAN_AND_MEAN -#include "dsound.h" -#ifndef USEKZ -#include //for fopen -#else -extern long kzopen (const char *); -extern long kzread (void *, long); -extern long kzseek (long, long); -extern void kzclose (); -extern long kzeof (); -#endif -#define DSOUNDINITCOM 1 //0=Link DSOUND.DLL, 1=Use COM interface to init DSOUND -#ifndef USEKENSOUND -#define USEKENSOUND 1 //0=playsound undefined (umixer only), 1=Ken's fancy sound renderer, 2=Standard Directsound secondary buffers -#endif -#define USETHREADS 20 //0=Disable, nonzero=enable multithreading and this is sleep value (20 is good) - //Use threads to fix audio gaps (and possibly other bugs too!) -#else -#define USETHREADS 0 -#endif - -#if ((USEKENSOUND == 1) && (USETHREADS != 0)) - //WinXP:Sleep(0)=infinite,Sleep(1-16)=64hz,Sleep(17-32)=32hz,Sleep(33-48)=21.3hz, etc...) - //Remember to add /MD, /MT or /link libcmt.lib kernel32.lib /nodefaultlib to compile options! -#include -static HANDLE hmutx; -#define ENTERMUTX WaitForSingleObject(hmutx,USETHREADS) //Do NOT use ,INFINITE) - too dangerous! -#define LEAVEMUTX ReleaseMutex(hmutx) -#else -#define ENTERMUTX -#define LEAVEMUTX -#endif - -#pragma warning(disable:4730) -#pragma warning(disable:4731) - -char *prognam = "Voxelstein3D"; -long progresiz = 1; -long progwndflags, progwndx = 0x80000000, progwndy, progwndadd[2]; -#ifndef NOINPUT -long dinputkeyboardflags = DISCL_NONEXCLUSIVE|DISCL_FOREGROUND; -long dinputmouseflags = DISCL_EXCLUSIVE|DISCL_FOREGROUND; -#endif - -#define WM_MOUSEWHEEL 0x020A - -extern long initapp (long argc, char **argv); -extern void initapp2(); -extern void uninitapp (); -extern void doframe (); - -static long quitprogram = 0, quitparam; -void breath(); - -void (*MenuFunc)(int iID, HANDLE hComponent) = NULL; - - //Global window variables -static WNDCLASS wc; -HWND ghwnd; -HINSTANCE ghinst, ghpinst; -LPSTR gcmdline; -int gncmdshow; - -long ActiveApp = 1, alwaysactive = 0; -long xres = 640, yres = 480, colbits = 8, fullscreen = 1, maxpages = 8; - - // Note! Without clipper blit is faster but only with software bliter -//#define NO_CLIPPER - -//======================== CPU detection code begins ======================== - -static long cputype = 0; -static OSVERSIONINFO osvi; - -#ifdef __WATCOMC__ - -long testflag (long); -#pragma aux testflag =\ - "pushfd"\ - "pop eax"\ - "mov ebx, eax"\ - "xor eax, ecx"\ - "push eax"\ - "popfd"\ - "pushfd"\ - "pop eax"\ - "xor eax, ebx"\ - "mov eax, 1"\ - "jne menostinx"\ - "xor eax, eax"\ - "menostinx:"\ - parm nomemory [ecx]\ - modify exact [eax ebx]\ - value [eax] - -void cpuid (long, long *); -#pragma aux cpuid =\ - ".586"\ - "cpuid"\ - "mov dword ptr [esi], eax"\ - "mov dword ptr [esi+4], ebx"\ - "mov dword ptr [esi+8], ecx"\ - "mov dword ptr [esi+12], edx"\ - parm [eax][esi]\ - modify exact [eax ebx ecx edx]\ - value - -#endif -#ifdef _MSC_VER - -#pragma warning(disable:4799) //I know how to use EMMS - -static _inline long testflag (long c) -{ - _asm - { - mov ecx, c - pushfd - pop eax - mov edx, eax - xor eax, ecx - push eax - popfd - pushfd - pop eax - xor eax, edx - mov eax, 1 - jne menostinx - xor eax, eax - menostinx: - } -} - -static _inline void cpuid (long a, long *s) -{ - _asm - { - push ebx - push esi - mov eax, a - cpuid - mov esi, s - mov dword ptr [esi+0], eax - mov dword ptr [esi+4], ebx - mov dword ptr [esi+8], ecx - mov dword ptr [esi+12], edx - pop esi - pop ebx - } -} - -#endif - - //Bit numbers of return value: - //0:FPU, 4:RDTSC, 15:CMOV, 22:MMX+, 23:MMX, 25:SSE, 26:SSE2, 30:3DNow!+, 31:3DNow! -static long getcputype () -{ - long i, cpb[4], cpid[4]; - if (!testflag(0x200000)) return(0); - cpuid(0,cpid); if (!cpid[0]) return(0); - cpuid(1,cpb); i = (cpb[3]&~((1<<22)|(1<<30)|(1<<31))); - cpuid(0x80000000,cpb); - if (((unsigned long)cpb[0]) > 0x80000000) - { - cpuid(0x80000001,cpb); - i |= (cpb[3]&(1<<31)); - if (!((cpid[1]^0x68747541)|(cpid[3]^0x69746e65)|(cpid[2]^0x444d4163))) //AuthenticAMD - i |= (cpb[3]&((1<<22)|(1<<30))); - } - if (i&(1<<25)) i |= (1<<22); //SSE implies MMX+ support - return(i); -} - -//========================= CPU detection code ends ========================= - -//================== Fast & accurate TIMER FUNCTIONS begins ================== - -#if 0 -#ifdef __WATCOMC__ - -__int64 rdtsc64 (); -#pragma aux rdtsc64 = "rdtsc" value [edx eax] modify nomemory parm nomemory; - -#endif -#ifdef _MSC_VER - -static __forceinline __int64 rdtsc64 () { _asm rdtsc } - -#endif - -static __int64 pertimbase, rdtimbase, nextimstep; -static double perfrq, klockmul, klockadd; - -void initklock () -{ - __int64 q; - QueryPerformanceFrequency((LARGE_INTEGER *)&q); - perfrq = (double)q; - rdtimbase = rdtsc64(); - QueryPerformanceCounter((LARGE_INTEGER *)&pertimbase); - nextimstep = 4194304; klockmul = 0.000000001; klockadd = 0.0; -} - -void readklock (double *tim) -{ - __int64 q = rdtsc64()-rdtimbase; - if (q > nextimstep) - { - __int64 p; - double d; - QueryPerformanceCounter((LARGE_INTEGER *)&p); - d = klockmul; klockmul = ((double)(p-pertimbase))/(((double)q)*perfrq); - klockadd += (d-klockmul)*((double)q); - do { nextimstep <<= 1; } while (q > nextimstep); - } - (*tim) = ((double)q)*klockmul + klockadd; -} -#else - -static __int64 klocksub; -static double klockmul; - -void initklock () -{ - __int64 q; - QueryPerformanceFrequency((LARGE_INTEGER *)&q); - klockmul = 1.0/((double)q); - QueryPerformanceCounter((LARGE_INTEGER *)&klocksub); -} - -void readklock (double *tim) -{ - __int64 q; - QueryPerformanceCounter((LARGE_INTEGER *)&q); - (*tim) = ((double)(q-klocksub))*klockmul; -} - -#endif - -//=================== Fast & accurate TIMER FUNCTIONS ends =================== - -//DirectDraw VARIABLES & CODE--------------------------------------------------------------- -#ifndef NODRAW - -PALETTEENTRY pal[256]; -long ddrawuseemulation = 0; -long ddrawdebugmode = -1; // -1 = off, old ddrawuseemulation = on - -static __int64 mask8a = 0x00ff00ff00ff00ff; -static __int64 mask8b; //0x10000d0010000d00 (fullscreen), 0x10000c0010000c00 (windowed) -static __int64 mask8c = 0x0000f8000000f800; -static __int64 mask8d = 0xff000000ff000000; -static __int64 mask8e = 0x00ff000000ff0000; -static __int64 mask8f; //0x00d000d000d000d0 (fullscreen), 0x0aca0aca0aca0aca (windowed) -static __int64 mask8g; //0xd000d000d000d000 (fullscreen), 0xca0aca0aca0aca0a (windowed) -static long mask8cnt = 0; -static __int64 mask8h = 0x0007050500070505; -static __int64 mask8lut[8] = -{ - 0x0000000000000000,0x0000001300000013, - 0x0000080000000800,0x0000081300000813, - 0x0010000000100000,0x0010001300100013, - 0x0010080000100800,0x0010081300100813 -}; -static __int64 maskrb15 = 0x00f800f800f800f8; -static __int64 maskgg15 = 0x0000f8000000f800; -static __int64 maskml15 = 0x2000000820000008; -static __int64 maskrb16 = 0x00f800f800f800f8; -static __int64 maskgg16 = 0x0000fc000000fc00; -static __int64 maskml16 = 0x2000000420000004; -static __int64 mask16a = 0x0000800000008000; -static __int64 mask16b = 0x8000800080008000; -static __int64 mask24a = 0x00ffffff00000000; -static __int64 mask24b = 0x00000000ffffff00; -static __int64 mask24c = 0x0000000000ffffff; -static __int64 mask24d = 0xffffff0000000000; - -static long lpal[256]; - - //Beware of alignment issues!!! -void kblit32 (long rplc, long rbpl, long rxsiz, long rysiz, - long wplc, long cdim, long wbpl) -{ -#ifdef _MSC_VER - if ((rxsiz <= 0) || (rysiz <= 0)) return; - if (colbits == 8) - { - long x, y; - switch(cdim) - { - case 15: case 16: - //for(y=0;yx = x; valptr->y = y; - if (ddpf->dwFlags&DDPF_PALETTEINDEXED8) { valptr->c = 8; return; } - if (ddpf->dwFlags&DDPF_RGB) - { - valptr->c = (char)ddpf->dwRGBBitCount; - if (ddpf->dwRBitMask) - { - valptr->r0 = (char)bsf(ddpf->dwRBitMask); - valptr->rn = (char)(bsr(ddpf->dwRBitMask)-(valptr->r0)+1); - } - if (ddpf->dwGBitMask) - { - valptr->g0 = (char)bsf(ddpf->dwGBitMask); - valptr->gn = (char)(bsr(ddpf->dwGBitMask)-(valptr->g0)+1); - } - if (ddpf->dwBBitMask) - { - valptr->b0 = (char)bsf(ddpf->dwBBitMask); - valptr->bn = (char)(bsr(ddpf->dwBBitMask)-(valptr->b0)+1); - } - if (ddpf->dwRGBAlphaBitMask) - { - valptr->a0 = (char)bsf(ddpf->dwRGBAlphaBitMask); - valptr->an = (char)(bsr(ddpf->dwRGBAlphaBitMask)-(valptr->a0)+1); - } - } -} - -HRESULT WINAPI lpEnumModesCallback (LPDDSURFACEDESC dsd, LPVOID lpc) -{ - grabmodeinfo(dsd->dwWidth,dsd->dwHeight,&dsd->ddpfPixelFormat,&validmodelist[validmodecnt]); validmodecnt++; - if (validmodecnt >= MAXVALIDMODES) return(DDENUMRET_CANCEL); else return(DDENUMRET_OK); -} - -long getvalidmodelist (validmodetype **davalidmodelist) -{ - if (!lpdd) return(0); - if (!validmodecnt) lpdd->EnumDisplayModes(0,0,0,lpEnumModesCallback); - (*davalidmodelist) = validmodelist; - return(validmodecnt); -} - -void uninitdirectdraw () -{ - if (ddpal) { ddpal->Release(); ddpal = 0; } - if (lpdd) - { -#ifndef NO_CLIPPER - if (ddcliprd) { free(ddcliprd); ddcliprd = 0; ddcliprdbytes = 0; } - if (ddclip) { ddclip->Release(); ddclip = 0; } -#endif - if (ddsurf[0]) { ddsurf[0]->Release(); ddsurf[0] = 0; } - if (ddrawemulbuf) { free(ddrawemulbuf); ddrawemulbuf = 0; } - lpdd->Release(); lpdd = 0; - } -} - -void updatepalette (long start, long danum) -{ - long i; - if (colbits == 8) - { - switch(ddrawuseemulation) - { - case 15: - for(i=start+danum-1;i>=start;i--) - lpal[i] = (((pal[i].peRed>>3)&31)<<10) + (((pal[i].peGreen>>3)&31)<<5) + ((pal[i].peBlue>>3)&31); - return; - case 16: - for(i=start+danum-1;i>=start;i--) - lpal[i] = (((pal[i].peRed>>3)&31)<<11) + (((pal[i].peGreen>>2)&63)<<5) + ((pal[i].peBlue>>3)&31); - return; - case 24: case 32: - for(i=start+danum-1;i>=start;i--) - lpal[i] = ((pal[i].peRed)<<16) + ((pal[i].peGreen)<<8) + pal[i].peBlue; - return; - default: break; - } - } - if (!ddpal) return; - if (ddpal->SetEntries(0,start,danum,&pal[start]) == DDERR_SURFACELOST) - { ddsurf[0]->Restore(); ddpal->SetEntries(0,start,danum,&pal[start]); } -} - - //((z/(16-1))^.8)*255, ((z/(32-1))^.8)*255, ((z/((13 fullscreen/12 windowed)-1))^.8)*255 -static char palr[16] = {0,29,51,70,89,106,123,139,154,169,184,199,213,227,241,255}; -static char palg[32] = {0,16,28,39,50,59,69,78,86,95,103,111,119,127,135,143, - 150,158,165,172,180,187,194,201,208,215,222,228,235,242,248,255}; -static char palb[16] = {0,35,61,84,106,127,146,166,184,203,220,238,255,0,0,0}; - -void emul8setpal () -{ - long i, r, g, b; - - if (fullscreen) - { - //13 shades of blue in fullscreen mode - *(long *)&palb[0] = 0+( 35<<8)+( 61<<16)+( 84<<24); - *(long *)&palb[4] = 106+(127<<8)+(146<<16)+(166<<24); - *(long *)&palb[8] = 184+(203<<8)+(220<<16)+(238<<24); - mask8b = 0x10000d0010000d00; - mask8f = 0x00d000d000d000d0; - mask8g = 0xd000d000d000d000; - - i = 0; - for(b=0;b<13;b++) - for(r=0;r<16;r++) - { - pal[i].peRed = palr[r]; - pal[i].peGreen = 0; - pal[i].peBlue = palb[b]; - pal[i].peFlags = PC_NOCOLLAPSE; - i++; - } //224 cols - for(g=0;g<32;g++) - { - pal[i].peRed = 0; - pal[i].peGreen = palg[g]; - pal[i].peBlue = 0; - pal[i].peFlags = PC_NOCOLLAPSE; - i++; - } - } - else - { - //12 shades of blue in fullscreen mode - *(long *)&palb[0] = 0+( 37<<8)+( 65<<16)+( 90<<24); - *(long *)&palb[4] = 114+(136<<8)+(157<<16)+(178<<24); - *(long *)&palb[8] = 198+(217<<8)+(236<<16)+(255<<24); - mask8b = 0x10000c0010000c00; - mask8f = 0x0aca0aca0aca0aca; - mask8g = 0xca0aca0aca0aca0a; - - for(i=0;i<10;i++) { pal[i].peFlags = PC_EXPLICIT; pal[i].peRed = (char)i; pal[i].peGreen = pal[i].peBlue = 0; } - for(b=0;b<12;b++) - for(r=0;r<16;r++) - { - pal[i].peRed = palr[r]; - pal[i].peGreen = 0; - pal[i].peBlue = palb[b]; - pal[i].peFlags = PC_NOCOLLAPSE; - i++; - } //192 cols - for(g=0;g<32;g++) - { - pal[i].peRed = 0; - pal[i].peGreen = palg[g]; - pal[i].peBlue = 0; - pal[i].peFlags = PC_NOCOLLAPSE; - i++; - } - for(;i<256-10;i++) { pal[i].peFlags = PC_NOCOLLAPSE; pal[i].peRed = pal[i].peGreen = pal[i].peBlue = 0; } - for(;i<256;i++) { pal[i].peFlags = PC_EXPLICIT; pal[i].peRed = (char)i; pal[i].peGreen = pal[i].peBlue = 0; } - } -} - - // Note! - // debugmode is automatically turned off after changeres or initdirectdraw! - // do NOT call debugdirectdraw inside startdirectdraw()..stopdirectdraw() section -void debugdirectdraw () -{ -#ifndef NOINPUT - extern long mouse_acquire, kbd_acquire; - extern void setacquire (long mouse, long kbd); - static long old_acq = 0; -#endif - if (ddrawdebugmode == -1) { - if (!ddrawuseemulation) { - ddrawemulbuf = malloc(((xres*yres+7)&~7)*((colbits+7)>>3)+16); if (!ddrawemulbuf) return; // error! - ddrawemulbpl = ((colbits+7)>>3)*xres; - ddrawdebugmode = 0; - ddrawuseemulation = 32; - } else - ddrawdebugmode = ddrawuseemulation; -#ifndef NOINPUT - old_acq = (mouse_acquire&1) + ((kbd_acquire&1)<<1); - setacquire(0,0); -#endif - } else { - ddrawuseemulation = ddrawdebugmode; - if (!ddrawuseemulation) { - if (ddrawemulbuf) { free(ddrawemulbuf); ddrawemulbuf = 0; } - } - ddrawdebugmode = -1; -#ifndef NOINPUT - setacquire(old_acq&1, old_acq>>1); -#endif - } -} - -long initdirectdraw (long daxres, long dayres, long dacolbits) -{ - HRESULT hr; - DDSCAPS ddscaps; - char buf[256]; - long ncolbits; - - xres = daxres; yres = dayres; colbits = dacolbits; -#ifndef REFRESHACK - if ((hr = DirectDrawCreate(0,&lpdd,0)) >= 0) - { -#else - if ((hr = DirectDrawCreate(0,&lpdd0,0)) >= 0) - { - lpdd0->QueryInterface(IID_IDirectDraw2,(void **)&lpdd); -#endif - if (fullscreen) - { - if ((hr = lpdd->SetCooperativeLevel(ghwnd,DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN)) >= 0) - { - ddrawdebugmode = -1; - ncolbits = dacolbits; ddrawuseemulation = 0; - //ncolbits = 8; //HACK FOR TESTING! - //ncolbits = 16; //HACK FOR TESTING! - do - { -#ifndef REFRESHACK - if ((hr = lpdd->SetDisplayMode(daxres,dayres,ncolbits)) >= 0) -#else - if ((hr = lpdd->SetDisplayMode(daxres,dayres,ncolbits,refreshz,0)) >= 0) -#endif - { - if (1)//(ncolbits != dacolbits) // FULLSCREEN ALPHA PERFORMANCE HACK! - { - ddrawemulbuf = malloc(((daxres*dayres+7)&~7)*((dacolbits+7)>>3)+16); - if (!ddrawemulbuf) { ncolbits = 0; break; } - ddrawemulbpl = ((dacolbits+7)>>3)*daxres; - ddrawuseemulation = ncolbits; - } - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE|DDSCAPS_COMPLEX|DDSCAPS_FLIP; - if (maxpages > 2) ddsd.dwBackBufferCount = 2; - else ddsd.dwBackBufferCount = 1; - if ((hr = lpdd->CreateSurface(&ddsd,&ddsurf[0],0)) >= 0) - { - DDPIXELFORMAT ddpf; - ddpf.dwSize = sizeof(DDPIXELFORMAT); - if (!ddsurf[0]->GetPixelFormat(&ddpf)) - grabmodeinfo(daxres,dayres,&ddpf,&curvidmodeinfo); - - ddscaps.dwCaps = DDSCAPS_BACKBUFFER; - if ((hr = ddsurf[0]->GetAttachedSurface(&ddscaps,&ddsurf[1])) >= 0) - { -#if (OFFSCREENHACK) - DDSURFACEDESC nddsd; - ddsurf[2] = ddsurf[1]; - ZeroMemory(&nddsd,sizeof(nddsd)); - nddsd.dwSize = sizeof(nddsd); - nddsd.dwFlags = DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT; - nddsd.dwWidth = (daxres|1); //This hack (|1) ensures pitch isn't near multiple of 4096 (slow on P4)! - nddsd.dwHeight = dayres; - nddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN|DDSCAPS_SYSTEMMEMORY; - if ((hr = lpdd->CreateSurface(&nddsd,&ddsurf[1],0)) < 0) return(-1); -#endif - if (ncolbits != 8) return(1); - if (lpdd->CreatePalette(DDPCAPS_8BIT,pal,&ddpal,0) >= 0) - { - ddsurf[0]->SetPalette(ddpal); - if (ddrawuseemulation) - { emul8setpal(); updatepalette(0,256); } - return(1); - } - } - } - } - switch(dacolbits) - { - case 8: - switch (ncolbits) - { - case 8: ncolbits = 32; break; - case 32: ncolbits = 24; break; - case 24: ncolbits = 16; break; - case 16: ncolbits = 15; break; - default: ncolbits = 0; break; - } - break; - case 32: - switch (ncolbits) - { - case 32: ncolbits = 24; break; - case 24: ncolbits = 16; break; - case 16: ncolbits = 15; break; - case 15: ncolbits = 8; break; - default: ncolbits = 0; break; - } - break; - default: ncolbits = 0; break; - } - } while (ncolbits); - if (!ncolbits) - { - validmodetype *validmodelist; - char vidlistbuf[4096]; - long i, j; - - validmodecnt = getvalidmodelist(&validmodelist); - wsprintf(vidlistbuf,"Valid fullscreen %d-bit DirectDraw modes:\n",colbits); - j = 0; - for(i=0;iSetCooperativeLevel(ghwnd,DDSCL_NORMAL)) >= 0) - { - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_CAPS; - ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE; - if ((hr = lpdd->CreateSurface(&ddsd,&ddsurf[0],0)) >= 0) - { -#ifndef NO_CLIPPER - //Create clipper object for windowed mode - if ((hr = lpdd->CreateClipper(0,&ddclip,0)) == DD_OK) - { - ddclip->SetHWnd(0,ghwnd); //Associate clipper with window - hr = ddsurf[0]->SetClipper(ddclip); - if (hr == DD_OK) - { -#endif - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; -#if (OFFSCREENHACK == 0) - ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; -#else - ddsd.ddsCaps.dwCaps = DDSCAPS_SYSTEMMEMORY; -#endif - ddsd.dwWidth = xres; - ddsd.dwHeight = yres; - if ((hr = lpdd->CreateSurface(&ddsd,&ddsurf[1],0)) >= 0) - { - DDCAPS ddcaps; - HDC hDC = GetDC(0); - ncolbits = GetDeviceCaps(hDC,BITSPIXEL); - ReleaseDC(0,hDC); - - ddcaps.dwSize = sizeof(ddcaps); - if (lpdd->GetCaps(&ddcaps,0) == DD_OK) //Better to catch DDERR_CANTLOCKSURFACE here than in startdirectdraw() - if (ddcaps.dwCaps&DDCAPS_NOHARDWARE) cantlockprimary = 1; //For LCD screens mainly - if (osvi.dwMajorVersion >= 6) cantlockprimary = 1; //Longhorn/Vista - - //03/08/2004: Now that clipper works for ddrawemulbuf, ddrawemulbuf is not only - //faster, but it supports WM_SIZE dragging better than ddsurf[0]->Blt! :) - // - //kblit32 currently supports these modes: - // colbits -> ncolbits - // 8 -> . 15 16 24 32 - // 15 -> . . . . . - // 16 -> . . . . . - // 24 -> . . . . . - // 32 -> 8 15 16 24 32 - if ((ncolbits != colbits) || ((colbits == 32) && (!cantlockprimary))) - { -#if (OFFSCREENHACK) - if (colbits != colbits) -#endif - { - ddrawemulbuf = malloc(((xres*yres+7)&~7)*((colbits+7)>>3)+16); - if (ddrawemulbuf) - { - ddrawemulbpl = ((colbits+7)>>3)*xres; - ddrawuseemulation = ncolbits; - if ((ncolbits == 8) && (colbits == 32)) emul8setpal(); - } - } - } - - if ((ncolbits == 8) || (colbits == 8)) updatepalette(0,256); - - DDPIXELFORMAT ddpf; - ddpf.dwSize = sizeof(DDPIXELFORMAT); - if (!ddsurf[0]->GetPixelFormat(&ddpf)) //colbits = ddpf.dwRGBBitCount; - { - grabmodeinfo(daxres,dayres,&ddpf,&curvidmodeinfo); - - //If mode is 555 color (and not 565), use 15-bit emulation code... - if ((colbits != 16) && (ncolbits == 16) - && (curvidmodeinfo.r0 == 10) && (curvidmodeinfo.rn == 5) - && (curvidmodeinfo.g0 == 5) && (curvidmodeinfo.gn == 5) - && (curvidmodeinfo.b0 == 0) && (curvidmodeinfo.bn == 5)) - ddrawuseemulation = 15; - } - - if (ncolbits == 8) - if (lpdd->CreatePalette(DDPCAPS_8BIT,pal,&ddpal,0) >= 0) - ddsurf[0]->SetPalette(ddpal); - - return(1); - } -#ifndef NO_CLIPPER - } - } -#endif - } - } - } - } - uninitdirectdraw(); - wsprintf(buf,"initdirectdraw failed: 0x%08lx",hr); - MessageBox(ghwnd,buf,"ERROR",MB_OK); - return(0); -} - -void stopdirectdraw () -{ - if (!ddlocked) return; - if (!ddrawuseemulation) ddsurf[1]->Unlock(ddsd.lpSurface); - ddlocked = 0; -} - -long startdirectdraw (long *vidplc, long *dabpl, long *daxres, long *dayres) -{ - HRESULT hr; - - if (ddlocked) { stopdirectdraw(); ddlocked = 0; } //{ return(0); } - - if (ddrawuseemulation) - { - *vidplc = (long)ddrawemulbuf; *dabpl = xres*((colbits+7)>>3); - *daxres = xres; *dayres = yres; ddlocked = 1; - return(1); - } - - while (1) - { - if ((hr = ddsurf[1]->Lock(0,&ddsd,DDLOCK_SURFACEMEMORYPTR|DDLOCK_WAIT,0)) == DD_OK) break; - if (hr == DDERR_SURFACELOST) - { - if (ddsurf[0]->Restore() != DD_OK) return(0); - if (ddsurf[1]->Restore() != DD_OK) return(0); - } - if (hr == DDERR_CANTLOCKSURFACE) return(-1); //if true, set cantlockprimary = 1; - if (hr != DDERR_WASSTILLDRAWING) return(0); - } - - //DDLOCK_WAIT MANDATORY! (to prevent sudden exit back to windows)! - //if (hr = ddsurf[1]->Lock(0,&ddsd,DDLOCK_SURFACEMEMORYPTR|DDLOCK_WAIT,0) != DD_OK) - // return(0); - - *vidplc = (long)ddsd.lpSurface; *dabpl = ddsd.lPitch; - *daxres = xres; *dayres = yres; ddlocked = 1; - return(1); -} - -static HDC ghdc; -HDC startdc () -{ - ddsurf[1]->GetDC(&ghdc); - return(ghdc); -} - -void stopdc () -{ - ddsurf[1]->ReleaseDC(ghdc); -} - -void nextpage () -{ - HRESULT hr; - - if (ddrawdebugmode != -1) return; - - //Note: windowed mode could be faster by having kblit go directly - // to the ddsurf[0] (windows video memory) - if (ddrawuseemulation) - { - long i, fplace, bpl, xsiz, ysiz; - if (!fullscreen) - { - POINT topLeft, p2; - long j; -#ifndef NO_CLIPPER - RECT *r; - unsigned long siz; -#endif - - //Note: this hack for windowed mode saves an unnecessary blit by - // going directly to primary buffer (ddsurf[0]) - // Unfortunately, this means it ignores the clipper & you can't - // use the ddraw stretch function :/ - topLeft.x = 0; topLeft.y = 0; - if (!cantlockprimary) - { - ddsurf[2] = ddsurf[0]; ddsurf[0] = ddsurf[1]; ddsurf[1] = ddsurf[2]; - ClientToScreen(ghwnd,&topLeft); - } - else - { - p2.x = 0; p2.y = 0; - ClientToScreen(ghwnd,&p2); - } - - //This is sort of a hack... but it works - i = ddrawuseemulation; ddrawuseemulation = 0; - j = startdirectdraw(&fplace,&bpl,&xsiz,&ysiz); - if (j == -1) - { - if (!cantlockprimary) - { - ddsurf[2] = ddsurf[0]; ddsurf[0] = ddsurf[1]; ddsurf[1] = ddsurf[2]; //Undo earlier surface swap - cantlockprimary = 1; ddrawuseemulation = i; return; - } - } - else if (j) - { -#ifndef NO_CLIPPER - ddclip->GetClipList(0,0,&siz); - if (siz > ddcliprdbytes) - { - ddcliprdbytes = siz; - ddcliprd = (RGNDATA *)realloc(ddcliprd,siz); - } - if (!ddcliprd) - { -#endif - kblit32(max(-topLeft.y,0)*ddrawemulbpl + - max(-topLeft.x,0)*((colbits+7)>>3) + ((long)ddrawemulbuf), - ddrawemulbpl, - min(topLeft.x+xsiz,GetSystemMetrics(SM_CXSCREEN))-max(topLeft.x,0), - min(topLeft.y+ysiz,GetSystemMetrics(SM_CYSCREEN))-max(topLeft.y,0), - max(topLeft.y,0)*bpl+max(topLeft.x,0)*((i+7)>>3)+fplace, - i,bpl); -#ifndef NO_CLIPPER - } - else - { - ddclip->GetClipList(0,ddcliprd,&siz); - - r = (RECT *)ddcliprd->Buffer; - for(j=0;j<(long)ddcliprd->rdh.nCount;j++) - { - if (cantlockprimary) { r[j].left -= p2.x; r[j].top -= p2.y; r[j].right -= p2.x; r[j].bottom -= p2.y; } - kblit32(max(r[j].top -topLeft.y,0)*ddrawemulbpl + - max(r[j].left-topLeft.x,0)*((colbits+7)>>3) + ((long)ddrawemulbuf), - ddrawemulbpl, - min(topLeft.x+xsiz,r[j].right )-max(topLeft.x,r[j].left), - min(topLeft.y+ysiz,r[j].bottom)-max(topLeft.y,r[j].top ), - max(topLeft.x,r[j].left)*((i+7)>>3) + - max(topLeft.y,r[j].top )*bpl + fplace, - i,bpl); - } - } -#endif - stopdirectdraw(); - } - ddrawuseemulation = i; - - //Finish windowed mode hack to primary buffer - if (!cantlockprimary) { ddsurf[2] = ddsurf[0]; ddsurf[0] = ddsurf[1]; ddsurf[1] = ddsurf[2]; return; } - } - else - { - //This is sort of a hack... but it works - i = ddrawuseemulation; ddrawuseemulation = 0; - if (startdirectdraw(&fplace,&bpl,&xsiz,&ysiz)) - { - kblit32((long)ddrawemulbuf,ddrawemulbpl,min(xsiz,xres),min(ysiz,yres),fplace,i,bpl); - stopdirectdraw(); - } - ddrawuseemulation = i; - } - } - - if (fullscreen) - { -#if (OFFSCREENHACK) - RECT r; r.left = 0; r.top = 0; r.right = xres; r.bottom = yres; //with width hack, src rect not always: xres,yres - if (ddsurf[2]->GetBltStatus(DDGBS_CANBLT) == DDERR_WASSTILLDRAWING) return; - if (ddsurf[2]->BltFast(0,0,ddsurf[1],&r,DDBLTFAST_NOCOLORKEY) == DDERR_SURFACELOST) - { ddsurf[0]->Restore(); if (ddsurf[2]->BltFast(0,0,ddsurf[1],&r,DDBLTFAST_NOCOLORKEY) != DD_OK) return; } - if (ddsurf[0]->GetFlipStatus(DDGFS_CANFLIP) == DDERR_WASSTILLDRAWING) return; //wait for blit to complete - if (ddsurf[0]->Flip(0,0) == DDERR_SURFACELOST) { ddsurf[0]->Restore(); ddsurf[0]->Flip(0,0); } -#elif 1 - //NOTE! If not using DDFLIP_WAIT, >70fps only works - // when ddsd.dwBackBufferCount > 1 (triple+ buffering) - while (1) //Recommended flipper from 1997 DirectDraw 3.0 MSDN CD: - { - if ((hr = ddsurf[0]->Flip(0,DDFLIP_WAIT)) == DD_OK) break; - if (hr == DDERR_SURFACELOST) - { - if (ddsurf[0]->Restore() != DD_OK) break; - if (ddsurf[1]->Restore() != DD_OK) break; - } - if (hr != DDERR_WASSTILLDRAWING) break; - } -#else - //This loop allows windows to breath while waiting for the flip - // so, it gives smoother execution - // WARNING: bad things can happen if breath() receives WM_CLOSE!!! - while (1) - { - if ((hr = ddsurf[0]->Flip(0,0)) == DD_OK) break; - if (hr == DDERR_WASSTILLDRAWING) { breath(); continue; } - if (hr == DDERR_SURFACELOST) - { - if (ddsurf[0]->Restore() != DD_OK) break; - if (ddsurf[1]->Restore() != DD_OK) break; - } - break; - } -#endif - } - else - { - RECT rcSrc, rcDst; - POINT topLeft; - - rcSrc.left = 0; rcSrc.top = 0; - rcSrc.right = xres; rcSrc.bottom = yres; -#ifndef ZOOM_TEST - rcDst = rcSrc; -#else - GetClientRect(ghwnd, &rcDst); -#endif - topLeft.x = 0; topLeft.y = 0; - ClientToScreen(ghwnd,&topLeft); - rcDst.left += topLeft.x; rcDst.right += topLeft.x; - rcDst.top += topLeft.y; rcDst.bottom += topLeft.y; -#ifdef NO_CLIPPER - if (ddsurf[0]->BltFast(rcDst.left,rcDst.top,ddsurf[1],&rcSrc,DDBLTFAST_WAIT|DDBLTFAST_NOCOLORKEY) < 0) -#else - if (ddsurf[0]->Blt(&rcDst,ddsurf[1],&rcSrc,DDBLT_WAIT|DDBLT_ASYNC,0) < 0) -#endif - { - if (ddsurf[0]->IsLost() == DDERR_SURFACELOST) ddsurf[0]->Restore(); - if (ddsurf[1]->IsLost() == DDERR_SURFACELOST) ddsurf[1]->Restore(); -#ifdef NO_CLIPPER - ddsurf[0]->BltFast(rcDst.left,rcDst.top,ddsurf[1],&rcSrc,DDBLTFAST_WAIT|DDBLTFAST_NOCOLORKEY); -#else - ddsurf[0]->Blt(&rcDst,ddsurf[1],&rcSrc,DDBLT_WAIT|DDBLT_ASYNC,0); -#endif - } - } -} - -void ddflip2gdi () -{ - if (lpdd) lpdd->FlipToGDISurface(); -} - -long clearscreen (long fillcolor) -{ - DDBLTFX blt; - HRESULT hr; - - if (ddrawuseemulation) - { - long c = ((xres*yres+7)&~7)*((colbits+7)>>3); c >>= 3; - if (cputype&(1<<25)) //SSE - { - _asm - { - mov edx, ddrawemulbuf - mov ecx, c - movd mm0, fillcolor - punpckldq mm0, mm0 - clear32a: movntq qword ptr [edx], mm0 - add edx, 8 - sub ecx, 1 - jnz short clear32a - emms - } - } - else if (cputype&(1<<23)) //MMX - { - _asm - { - mov edx, ddrawemulbuf - mov ecx, c - movd mm0, fillcolor - punpckldq mm0, mm0 - clear32b: movq qword ptr [edx], mm0 - add edx, 8 - sub ecx, 1 - jnz short clear32b - emms - } - } - else - { - long q[2]; q[0] = q[1] = fillcolor; - _asm - { - mov edx, ddrawemulbuf - mov ecx, c - clear32c: fild qword ptr q - fistp qword ptr [edx] ;NOTE: fist doesn't have a 64-bit form! - add edx, 8 - sub ecx, 1 - jnz short clear32c - } - } - return(1); - } - - //Can't clear when locked: would SUPERCRASH! - if (ddlocked) - { - long i, j, x, p, pe; - - p = (long)ddsd.lpSurface; pe = ddsd.lPitch*yres + p; - if (colbits != 24) - { - switch(colbits) - { - case 8: fillcolor = (fillcolor&255)*0x1010101; i = xres ; break; - case 15: case 16: fillcolor = (fillcolor&65535)*0x10001; i = xres*2; break; - case 32: i = xres*4; break; - } - for(;p>3); - if (cputype&(1<<25)) //SSE - { - _asm - { - mov edx, p - mov ecx, j - movd mm0, fillcolor - punpckldq mm0, mm0 - clear32d: movntq qword ptr [edx], mm0 - add edx, 8 - sub ecx, 1 - jnz short clear32d - emms - } - } - else if (cputype&(1<<23)) //MMX - { - _asm - { - mov edx, p - mov ecx, j - movd mm0, fillcolor - punpckldq mm0, mm0 - clear32e: movq qword ptr [edx], mm0 - add edx, 8 - sub ecx, 1 - jnz short clear32e - emms - } - } - else - { - long q[2]; q[0] = q[1] = fillcolor; - _asm - { - mov edx, p - mov ecx, j - clear32f: fild qword ptr q - fistp qword ptr [edx] ;NOTE: fist doesn't have a 64-bit form! - add edx, 8 - sub ecx, 1 - jnz short clear32f - } - } - x = (i&~7)+p; - if (i&4) { *(long *)x = fillcolor; x += 4; } -#endif - if (i&2) { *(short *)x = (short)fillcolor; x += 2; } - if (i&1) { *(char *)x = (char)fillcolor; } - } - if (cputype&(1<<25)) _asm emms //SSE - } - else - { - long dacol[3]; - fillcolor &= 0xffffff; - dacol[0] = (fillcolor<<24)+fillcolor; //BRGB - dacol[1] = (fillcolor>>8)+(fillcolor<<16); //GBRG - dacol[2] = (fillcolor>>16)+(fillcolor<<8); //RGBR - i = xres*3; - for(;pBlt(0,0,0,DDBLT_COLORFILL,&blt); //Try |DDBLT_WAIT - if (hr == DD_OK) return(1); - if (hr == DDERR_SURFACELOST) - { - if (ddsurf[0]->Restore() != DD_OK) return(0); - if (ddsurf[1]->Restore() != DD_OK) return(0); - } - } -} - -long changeres (long daxres, long dayres, long dacolbits, long dafullscreen) -{ - uninitdirectdraw(); - - ShowWindow(ghwnd,FALSE); - if (dafullscreen) - { - SetWindowLong(ghwnd,GWL_EXSTYLE,WS_EX_TOPMOST); - SetWindowLong(ghwnd,GWL_STYLE,WS_POPUP); - MoveWindow(ghwnd,0,0,GetSystemMetrics(SM_CXSCREEN), - GetSystemMetrics(SM_CYSCREEN),0); - } - else - { - RECT rw; - SystemParametersInfo(SPI_GETWORKAREA,0,&rw,0); - - SetWindowLong(ghwnd,GWL_EXSTYLE, 0); - SetWindowLong(ghwnd,GWL_STYLE,progwndflags); - MoveWindow(ghwnd,((rw.right -rw.left-(daxres+progwndadd[0]))>>1) + rw.left, - ((rw.bottom-rw.top -(dayres+progwndadd[1]))>>1) + rw.top, - daxres+progwndadd[0], dayres+progwndadd[1], 0); - } - ShowWindow(ghwnd,TRUE); - - fullscreen = dafullscreen; - return(initdirectdraw(daxres,dayres,dacolbits)); -} - -// //How to use dc & draw text: -//HDC hdc; -//if (ddsurf[1]->GetDC(&hdc) == DD_OK) -//{ -// SetBkColor(hdc,RGB(0,0,255)); //SetBkMode(hdc,TRANSPARENT); -// SetTextColor(hdc,RGB(255,255,0)); -// //HFONT fontInUse = CreateFont(size,0,0,0,FW_NORMAL,0,0,0,ANSI_CHARSET,OUT_DEFAULT_PRECIS, -// // CLIP_DEFAULT_PRECIS,NONANTIALIASED_QUALITY,VARIABLE_PITCH,"Arial"); -// //oldFont = SelectObject(hdc,fontInUse); -// TextOut(hdc,x,y,message,strlen(message)); -// //SelectObject(hdc,oldFont); -// //DeleteObject(fontInUse); -// ddsurf[1]->ReleaseDC(hdc); -//} - -// //Do this to ensure GDI stuff is on the screen: -//lpdd->FlipToGDISurface(); - -// //Use real timers, (forget SetTimer/WM_TIMER crap): -//#include -//void CALLBACK OneShotTimer(UINT wTimerID, UINT msg, DWORD dwUser, DWORD dw1, DWORD dw2) -// { printf("Alarm!"); } -//timeSetEvent(msInterval,msInterval,OneShotTimer,(DWORD)npSeq,TIME_PERIODIC); -#endif - -//DirectInput VARIABLES & CODE------------------------------------------------------- -char keystatus[256]; -static long shkeystatus = 0; -#define KEYBUFSIZ 256 -static long keybuf[KEYBUFSIZ], keybufr = 0, keybufw = 0, keybufw2 = 0; - -char ext_keystatus[256]; // +TD -char ext_mbstatus[8] = {0}; // +TD extended mouse button status -long ext_mwheel = 0; -#ifdef NOINPUT -long mouse_acquire = 0; -#else -long mouse_acquire = 1, kbd_acquire = 1; -static void (*setmousein)(long, long) = NULL; -static long mouse_out_x, mouse_out_y; -static HANDLE dinputevent[2] = {0,0}; - -static LPDIRECTINPUT gpdi = 0; -long initdirectinput (HWND hwnd) -{ - HRESULT hr; - char buf[256]; - - if ((hr = DirectInput8Create(ghinst,DIRECTINPUT_VERSION,IID_IDirectInput8A,(LPVOID*)&gpdi,0)) >= 0) return(1); - wsprintf(buf,"initdirectinput failed: %08lx\n",hr); - MessageBox(ghwnd,buf,"ERROR",MB_OK); - return(0); -} - -void uninitdirectinput () -{ - if (gpdi) { gpdi->Release(); gpdi = 0; } -} - -//DirectInput (KEYBOARD) VARIABLES & CODE------------------------------------------------------- -static LPDIRECTINPUTDEVICE gpKeyboard = 0; -#define KBDBUFFERSIZE 64 -DIDEVICEOBJECTDATA KbdBuffer[KBDBUFFERSIZE]; - -//#define KEYBUFSIZ 256 -//static long keybuf[KEYBUFSIZ], keybufr = 0, keybufw = 0, keybufw2 = 0; - -void uninitkeyboard () -{ - if (gpKeyboard) - { - if (dinputevent[1]) - { - gpKeyboard->SetEventNotification(dinputevent[1]); - CloseHandle(dinputevent[1]); dinputevent[1] = 0; - } - gpKeyboard->Unacquire(); gpKeyboard->Release(); gpKeyboard = 0; - } -} - -long initkeyboard (HWND hwnd) -{ - HRESULT hr; - DIPROPDWORD dipdw; - char buf[256]; - - if ((hr = gpdi->CreateDevice(GUID_SysKeyboard,&gpKeyboard,0)) < 0) goto initkeyboard_bad; - if ((hr = gpKeyboard->SetDataFormat(&c_dfDIKeyboard)) < 0) goto initkeyboard_bad; - if ((hr = gpKeyboard->SetCooperativeLevel(hwnd,dinputkeyboardflags)) < 0) goto initkeyboard_bad; - - dinputevent[1] = CreateEvent(0,0,0,0); if (!dinputevent[1]) goto initkeyboard_bad; - if ((hr = gpKeyboard->SetEventNotification(dinputevent[1])) < 0) goto initkeyboard_bad; - - dipdw.diph.dwSize = sizeof(DIPROPDWORD); - dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - dipdw.dwData = KBDBUFFERSIZE; - if ((hr = gpKeyboard->SetProperty(DIPROP_BUFFERSIZE,&dipdw.diph)) < 0) goto initkeyboard_bad; - if (kbd_acquire) { gpKeyboard->Acquire(); shkeystatus = 0; } - return(1); - -initkeyboard_bad:; - uninitkeyboard(); - wsprintf(buf,"initdirectinput(keyboard) failed: %08lx\n",hr); - MessageBox(ghwnd,buf,"ERROR",MB_OK); - return(0); -} - -long readkeyboard () -{ - HRESULT hr; - long i; - unsigned long dwItems; - DIDEVICEOBJECTDATA *lpdidod; - - dwItems = KBDBUFFERSIZE; - hr = gpKeyboard->GetDeviceData(sizeof(DIDEVICEOBJECTDATA),KbdBuffer,&dwItems,0); - //if (hr == DI_BUFFEROVERFLOW) ?; - if (hr == DIERR_INPUTLOST) - { - gpKeyboard->Acquire(); shkeystatus = 0; - hr = gpKeyboard->GetDeviceData(sizeof(DIDEVICEOBJECTDATA),KbdBuffer,&dwItems,0); - } - if (hr < 0) return(0); - for(i=0;i<(long)dwItems;i++) - { - lpdidod = &KbdBuffer[i]; - - if (lpdidod->dwData&128) keystatus[lpdidod->dwOfs] = 1; - else keystatus[lpdidod->dwOfs] = 0; - //event occured "GetTickCount()-lpdidod->dwTimeStamp" milliseconds ago - - // +TD: - if (lpdidod->dwData&128) ext_keystatus[lpdidod->dwOfs] = 1|2; - else ext_keystatus[lpdidod->dwOfs] &= ~1; // preserve bit 2 only - } - return(dwItems); -} - - -//DirectInput (MOUSE) VARIABLES & CODE------------------------------------------------------- - -static LPDIRECTINPUTDEVICE gpMouse = 0; -#define MOUSBUFFERSIZE 64 -DIDEVICEOBJECTDATA MousBuffer[MOUSBUFFERSIZE]; -static long gbstatus = 0, gkillbstatus = 0; - - //Mouse smoothing variables: -long mousmoth = 1; -static double dmoutsc; -float mousper; -static float mousince, mougoalx, mougoaly, mougoalz, moutscale; -static long moult[4], moultavg, moultavgcnt; - -void uninitmouse () -{ - if (gpMouse) - { - if (dinputevent[0]) - { - gpMouse->SetEventNotification(dinputevent[0]); - CloseHandle(dinputevent[0]); dinputevent[0] = 0; - } - gpMouse->Unacquire(); gpMouse->Release(); gpMouse = 0; - } -} - -long initmouse (HWND hwnd) -{ - HRESULT hr; - DIPROPDWORD dipdw; - char buf[256]; - - if ((hr = gpdi->CreateDevice(GUID_SysMouse,&gpMouse,0)) < 0) goto initmouse_bad; - if ((hr = gpMouse->SetDataFormat(&c_dfDIMouse)) < 0) goto initmouse_bad; -#ifndef PROJECT_ANIMATOR - if ((hr = gpMouse->SetCooperativeLevel(hwnd,dinputmouseflags)) < 0) goto initmouse_bad; -#endif - - dinputevent[0] = CreateEvent(0,0,0,0); if (!dinputevent[0]) goto initmouse_bad; - if ((hr = gpMouse->SetEventNotification(dinputevent[0])) < 0) goto initmouse_bad; - - dipdw.diph.dwSize = sizeof(DIPROPDWORD); - dipdw.diph.dwHeaderSize = sizeof(DIPROPHEADER); - dipdw.diph.dwObj = 0; - dipdw.diph.dwHow = DIPH_DEVICE; - dipdw.dwData = MOUSBUFFERSIZE; - if ((hr = gpMouse->SetProperty(DIPROP_BUFFERSIZE, &dipdw.diph)) < 0) goto initmouse_bad; - - if (mouse_acquire) { gpMouse->Acquire(); gbstatus = 0; } - mousper = 1.0; mousince = mougoalx = mougoaly = mougoalz = 0.0; - moult[0] = -1; moultavg = moultavgcnt = 0; - readklock(&dmoutsc); - return(1); - -initmouse_bad:; - uninitmouse(); - wsprintf(buf,"initdirectinput(mouse) failed: %08lx\n",hr); - MessageBox(ghwnd,buf,"ERROR",MB_OK); - return(0); -} - -void readmouse (float *fmousx, float *fmousy, float *fmousz, long *bstatus) -{ - double odmoutsc; - float f, fmousynctics; - long i, got, ltmin, ltmax, nlt0, nlt1, nlt2; - long mousx, mousy, mousz; - HRESULT hr; - unsigned long dwItems; - DIDEVICEOBJECTDATA *lpdidod; - - if ((!mouse_acquire) || (!gpMouse)) { *fmousx = 0; *fmousy = 0; *fmousz = 0; *bstatus = 0; return; } - - dwItems = MOUSBUFFERSIZE; - hr = gpMouse->GetDeviceData(sizeof(DIDEVICEOBJECTDATA),MousBuffer,&dwItems,0); - if (hr == DI_BUFFEROVERFLOW) moult[0] = -1; - if (hr == DIERR_INPUTLOST) - { - gpMouse->Acquire(); gbstatus = 0; - hr = gpMouse->GetDeviceData(sizeof(DIDEVICEOBJECTDATA),MousBuffer,&dwItems,0); - } - - //Estimate mouse period (mousper) in units of CPU cycles: - mousx = mousy = mousz = 0; got = 0; - i = 0; lpdidod = &MousBuffer[i]; - while (i < (long)dwItems) - { - moult[3] = moult[2]; moult[2] = moult[1]; moult[1] = moult[0]; - moult[0] = lpdidod->dwTimeStamp; - do - { - switch(lpdidod->dwOfs) - { - case DIMOFS_X: mousx += lpdidod->dwData; break; - case DIMOFS_Y: mousy += lpdidod->dwData; break; - case DIMOFS_Z: mousz += lpdidod->dwData; break; - case DIMOFS_BUTTON0: if (lpdidod->dwData&128) ext_mbstatus[0] = 1|2; else ext_mbstatus[0] &= 2; - gbstatus = ((gbstatus&~1)|((lpdidod->dwData>>7)&1)); moult[0] = -1; break; - case DIMOFS_BUTTON1: if (lpdidod->dwData&128) ext_mbstatus[1] = 1|2; else ext_mbstatus[1] &= 2; - gbstatus = ((gbstatus&~2)|((lpdidod->dwData>>6)&2)); moult[0] = -1; break; - case DIMOFS_BUTTON2: if (lpdidod->dwData&128) ext_mbstatus[2] = 1|2; else ext_mbstatus[2] &= 2; - gbstatus = ((gbstatus&~4)|((lpdidod->dwData>>5)&4)); moult[0] = -1; break; - case DIMOFS_BUTTON3: if (lpdidod->dwData&128) ext_mbstatus[3] = 1|2; else ext_mbstatus[3] &= 2; - gbstatus = ((gbstatus&~8)|((lpdidod->dwData>>4)&8)); moult[0] = -1; break; - } - i++; lpdidod = &MousBuffer[i]; - } while ((i < (long)dwItems) && ((long)lpdidod->dwTimeStamp == moult[0])); - - if (moult[0] != -1) - { - got++; - if ((moult[1] != -1) && (moult[2] != -1) && (moult[3] != -1)) - { - nlt0 = moult[0]-moult[1]; - nlt1 = moult[1]-moult[2]; - nlt2 = moult[2]-moult[3]; - ltmin = nlt0; ltmax = nlt0; - if (nlt1 < ltmin) ltmin = nlt1; - if (nlt2 < ltmin) ltmin = nlt2; - if (nlt1 > ltmax) ltmax = nlt1; - if (nlt2 > ltmax) ltmax = nlt2; - if (ltmin*2 >= ltmax) //WARNING: NT's timer has 10ms resolution! - { - moultavg += moult[0]-moult[3]; moultavgcnt += 3; - mousper = (float)moultavg/(float)moultavgcnt; - } - } - } - } - if (gkillbstatus) { gkillbstatus = 0; gbstatus = 0; } //Flush packets after task switch - (*bstatus) = gbstatus; - - //Calculate and return smoothed mouse data in: (fmousx, fmousy) - odmoutsc = dmoutsc; readklock(&dmoutsc); - fmousynctics = (float)((dmoutsc-odmoutsc)*1000.0); - - //At one time, readklock() wasn't always returning increasing values. - //This made fmousynctics <= 0 possible, causing /0. Fixed now :) - if ((!moultavgcnt) || (!mousmoth)) //|| ((*(long *)&fmousynctics) <= 0)) - { (*fmousx) = (float)mousx; (*fmousy) = (float)mousy; (*fmousz) = (float)mousz; return; } - - mousince = min(mousince+mousper*(float)got,mousper+fmousynctics); - if (fmousynctics >= mousince) { f = 1; mousince = 0; } - else { f = fmousynctics / mousince; mousince -= fmousynctics; } - mougoalx += (float)mousx; (*fmousx) = mougoalx*f; mougoalx -= (*fmousx); - mougoaly += (float)mousy; (*fmousy) = mougoaly*f; mougoaly -= (*fmousy); - mougoalz += (float)mousz; (*fmousz) = mougoalz*f; mougoalz -= (*fmousz); -} -void readmouse (float *fmousx, float *fmousy, long *bstatus) -{ - float fmousz; - readmouse(fmousx,fmousy,&fmousz,bstatus); -} - -void smartsleep (long timeoutms) -{ - MsgWaitForMultipleObjects(2,dinputevent,0,timeoutms,QS_KEY|QS_PAINT); -} - -#endif - - -// Kensound code begins ------------------------------------------------------- - -#ifndef NOSOUND -//-------------------------------------------------------------------------------------------------- -#define MAXUMIXERS 256 -#define UMIXERBUFSIZ 65536 -typedef struct -{ - LPDIRECTSOUNDBUFFER streambuf; - long samplerate, numspeakers, bytespersample, oplaycurs; - void (*mixfunc)(void *dasnd, long danumbytes); -} umixertyp; -static umixertyp umixer[MAXUMIXERS]; -static long umixernum = 0; - -extern LPDIRECTSOUND dsound; //Defined later - -long umixerstart (void damixfunc (void *, long), long dasamprate, long danumspeak, long dabytespersamp) -{ - DSBUFFERDESC dsbdesc; - DSBCAPS dsbcaps; - WAVEFORMATEX wfx; - void *w0 = 0, *w1 = 0; - unsigned long l0 = 0, l1 = 0; - - if ((dasamprate <= 0) || (danumspeak <= 0) || (dabytespersamp <= 0) || (umixernum >= MAXUMIXERS)) return(-1); - - umixer[umixernum].samplerate = dasamprate; - umixer[umixernum].numspeakers = danumspeak; - umixer[umixernum].bytespersample = dabytespersamp; - - wfx.wFormatTag = WAVE_FORMAT_PCM; - wfx.nSamplesPerSec = dasamprate; - wfx.wBitsPerSample = (dabytespersamp<<3); - wfx.nChannels = danumspeak; - wfx.nBlockAlign = (wfx.wBitsPerSample>>3) * wfx.nChannels; - wfx.nAvgBytesPerSec = wfx.nSamplesPerSec * wfx.nBlockAlign; - wfx.cbSize = 0; - - memset(&dsbdesc,0,sizeof(DSBUFFERDESC)); - dsbdesc.dwSize = sizeof(DSBUFFERDESC); - dsbdesc.dwFlags = DSBCAPS_GETCURRENTPOSITION2|DSBCAPS_LOCSOFTWARE|DSBCAPS_GLOBALFOCUS; - dsbdesc.dwBufferBytes = UMIXERBUFSIZ; - dsbdesc.lpwfxFormat = &wfx; - if (dsound->CreateSoundBuffer(&dsbdesc,&umixer[umixernum].streambuf,0) != DS_OK) return(-1); - - //Zero out streaming buffer before beginning play - umixer[umixernum].streambuf->Lock(0,UMIXERBUFSIZ,&w0,&l0,&w1,&l1,0); - if (w0) memset(w0,(dabytespersamp-2)&128,l0); - if (w1) memset(w1,(dabytespersamp-2)&128,l1); - umixer[umixernum].streambuf->Unlock(w0,l0,w1,l1); - - umixer[umixernum].streambuf->SetCurrentPosition(0); - umixer[umixernum].streambuf->Play(0,0,DSBPLAY_LOOPING); - - umixer[umixernum].oplaycurs = 0; - umixer[umixernum].mixfunc = damixfunc; - umixernum++; - - return(umixernum-1); -} - -void umixerkill (long i) -{ - if ((unsigned long)i >= umixernum) return; - if (umixer[i].streambuf) - { umixer[i].streambuf->Stop(); umixer[i].streambuf->Release(); umixer[i].streambuf = 0; } - umixernum--; if (i != umixernum) umixer[i] = umixer[umixernum]; -} - -void umixerbreathe () -{ - void *w0 = 0, *w1 = 0; - unsigned long l, l0 = 0, l1 = 0, playcurs, writcurs; - long i; - - for(i=0;iGetCurrentPosition(&playcurs,&writcurs) != DS_OK) continue; - playcurs += ((umixer[i].samplerate/8)<<(umixer[i].bytespersample+umixer[i].numspeakers-2)); - l = (((playcurs-umixer[i].oplaycurs)&(UMIXERBUFSIZ-1))>>(umixer[i].bytespersample+umixer[i].numspeakers-2)); - if (l <= 256) continue; - if (umixer[i].streambuf->Lock(umixer[i].oplaycurs&(UMIXERBUFSIZ-1),l<<(umixer[i].bytespersample+umixer[i].numspeakers-2),&w0,&l0,&w1,&l1,0) != DS_OK) continue; - if (w0) umixer[i].mixfunc(w0,l0); - if (w1) umixer[i].mixfunc(w1,l1); - umixer[i].oplaycurs += l0+l1; - umixer[i].streambuf->Unlock(w0,l0,w1,l1); - } -} -//-------------------------------------------------------------------------------------------------- -typedef struct { float x, y, z; } point3d; -#if (USEKENSOUND == 1) -#include - - //Internal streaming buffer variables: -#define SNDSTREAMSIZ 16384 //(16384) Keep this a power of 2! -#define MINBREATHREND 256 //(256) Keep this high to avoid clicks, but much smaller than SNDSTREAMSIZ! -#define LSAMPREC 10 //(11) No WAV file can have more than 2^(31-LSAMPREC) samples -#define MAXPLAYINGSNDS 256 //(256) -#define VOLSEPARATION 1.f //(1.f) Range: 0 to 1, .5 good for headphones, 1 good for speakers -#define EARSEPARATION 8.f //(8.f) Used for L/R sample shifting -#define SNDMINDIST 32.f //(32.f) Shortest distance where volume is max / volume scale factor -#define SNDSPEED 4096.f //(4096.f) Speed of sound in units per second -#define NUMCOEF 4 //(4) # filter coefficients (4 and 8 are good choices) -#define LOGCOEFPREC 5 //(5) number of fractional bits of precision: 5 is ok -#define COEFRANG 32757 //(32757) DON'T make this > 32757 (not a typo) or else it'll overflow -#define KSND_3D 1 -#define KSND_MOVE 2 -#define KSND_LOOP 4 -#define KSND_LOPASS 8 -#define KSND_MEM 16 -#define KSND_LOOPFADE 32 //for internal use only - -typedef struct //For sounds longer than SNDSTREAMSIZ -{ - point3d *ptr; //followstat (-1 means not 3D sound, 0 means 3D sound but don't follow, else follow 3D!) - point3d p; //current position - long flags; //Bit0:1=3D, Bit1:1=follow 3D, Bit2:1=loop - long ssnd; //source sound - long ispos; //sub-sample counter (before doppler delay) - long ispos0; //L sub-sample counter - long ispos1; //R sub-sample counter - long isinc; //sub-sample increment - long ivolsc; //volume scale - long ivolsc0; //L volume scale - long ivolsc1; //R volume scale - short *coefilt; //pointer to coef (for low pass filter, etc...) -} rendersndtyp; -static rendersndtyp rendersnd[MAXPLAYINGSNDS]; -static long numrendersnd = 0; - -LPDIRECTSOUNDBUFFER streambuf = 0; -#endif -LPDIRECTSOUND dsound = 0; -#if (USEKENSOUND == 1) - - //format: (used by audplay* to cache filenames&files themselves) - //[index to next hashindex or -1][index to last filnam][ptr to snd_buf][char snd_filnam[?]\0] -#define AUDHASHINITSIZE 8192 -static char *audhashbuf = 0; -#define AUDHASHEADSIZE 256 //must be power of 2 -static long audhashead[AUDHASHEADSIZE], audhashpos, audlastloadedwav, audhashsiz; - -static point3d audiopos, audiostr, audiohei, audiofor; -static float rsamplerate; -static long lsnd[SNDSTREAMSIZ>>1], samplerate, numspeakers, bytespersample, oplaycurs = 0; -static char gshiftval = 0; -__declspec(align(16)) static short coef[NUMCOEF<= 'a') && (ch0 <= 'z')) ch0 -= 32; - ch1 = st1[i]; if ((ch1 >= 'a') && (ch1 <= 'z')) ch1 -= 32; - if (ch0 == '/') ch0 = '\\'; - if (ch1 == '/') ch1 = '\\'; - if (ch0 != ch1) return(-1); - } - if (!st1[i]) return(0); - return(-1); -} - -static long audcalchash (const char *st) -{ - long i, hashind; - char ch; - - for(i=0,hashind=0;st[i];i++) - { - ch = st[i]; - if ((ch >= 'a') && (ch <= 'z')) ch -= 32; - if (ch == '/') ch = '\\'; - hashind = (ch - hashind*3); - } - return(hashind&(AUDHASHEADSIZE-1)); -} - -static long audcheckhashsiz (long siz) -{ - long i; - - if (!audhashbuf) //Initialize hash table on first call - { - memset(audhashead,-1,sizeof(audhashead)); - if (!(audhashbuf = (char *)malloc(AUDHASHINITSIZE))) return(0); - audhashpos = 0; audlastloadedwav = -1; audhashsiz = AUDHASHINITSIZE; - } - if (audhashpos+siz > audhashsiz) //Make sure string fits in audhashbuf - { - i = audhashsiz; do { i <<= 1; } while (audhashpos+siz > i); - if (!(audhashbuf = (char *)realloc(audhashbuf,i))) return(0); - audhashsiz = i; - } - return(1); -} - -static void kensoundclose () -{ - numrendersnd = 0; - - ENTERMUTX; - if (streambuf) streambuf->Stop(); - - if (audhashbuf) - { - long i; - for(i=audlastloadedwav;i>=0;i=(*(long *)&audhashbuf[i+4])) - free((void *)(*(long *)&audhashbuf[i+8])); - free(audhashbuf); audhashbuf = 0; - } - audhashpos = audhashsiz = 0; - - if (streambuf) { streambuf->Release(); streambuf = 0; } - LEAVEMUTX; -} - -#define PI 3.14159265358979323 -static void initfilters () -{ - float f, f2, f3, f4, fcoef[NUMCOEF]; - long i, j, k, cenbias; - - //Generate polynomial filter - fewer divides algo. (See PIANO.C for derivation) - f4 = 1.0 / (float)(1<>1); - for(i=0;i<(1<CreateSoundBuffer(&bufdesc,&streambuf,0) != DS_OK) return(-1); - - //streambuf->SetVolume(curmusicvolume); - //streambuf->SetFrequency(curmusicfrequency); - //streambuf->SetPan(curmusicpan); - - //Zero out streaming buffer before beginning play - streambuf->Lock(0,SNDSTREAMSIZ,&w0,&l0,&w1,&l1,0); - if (w0) memset(w0,(bytespersample-2)&128,l0); - if (w1) memset(w1,(bytespersample-2)&128,l1); - streambuf->Unlock(w0,l0,w1,l1); - - initfilters(); - - streambuf->SetCurrentPosition(0); - streambuf->Play(0,0,DSBPLAY_LOOPING); - - return(0); -} - -static __forceinline long mulshr16 (long a, long d) -{ - _asm - { - mov eax, a - imul d - shrd eax, edx, 16 - } -} - -static __forceinline long mulshr32 (long a, long d) -{ - _asm - { - mov eax, a - imul d - mov eax, edx - } -} - - // ssnd: source sound - // ispos: sub-sample counter - // isinc: sub-sample increment per destination sample - // ivolsc: 31-bit volume scale - //ivolsci: 31-bit ivolsc increment per destination sample - // lptr: 32-bit sound pointer (step by 8 because rendersamps only renders 1 channel!) - // nsamp: number of destination samples to render -static void rendersamps (long dasnd, long ispos, long isinc, long ivolsc, long ivolsci, long *lptr, long nsamp, short *coefilt) -{ - long i, j, k; - - i = isinc*nsamp + ispos; if (i < isinc) return; //ispos < 0 for all samples! - j = *(long *)(dasnd-8); if ((ispos>>LSAMPREC) >= j) return; //ispos >= j for all samples! - //Clip off low ispos - if (ispos < 0) { k = (isinc-1-ispos)/isinc; ivolsc += ivolsci*k; ispos += isinc*k; lptr += k*2; nsamp -= k; } - if (((i-isinc)>>LSAMPREC) >= j) nsamp = ((j<>LSAMPREC],ivolsc); - ivolsc += ivolsci; ispos += isinc; lptr += 2; nsamp--; - } while (nsamp); -#elif (NUMCOEF == 2) - short *ssnd; //Fast sound rendering; ok quality - do - { - ssnd = (short *)(((ispos>>LSAMPREC)<<1)+dasnd); - lptr[0] += mulshr32((long)(((((long)ssnd[1])-((long)ssnd[0]))*(ispos&((1<>LSAMPREC)+((long)ssnd[0]),ivolsc); - ivolsc += ivolsci; ispos += isinc; lptr += 2; nsamp--; - } while (nsamp); -#elif (NUMCOEF == 4) -#if 0 - short *soef, *ssnd; //Slow sound rendering; great quality - do - { - ssnd = (short *)(((ispos>>LSAMPREC)<<1)+dasnd); - soef = &coef[((ispos&((1<>(LSAMPREC-LOGCOEFPREC))<<2]; - lptr[0] += mulshr32((long)ssnd[0]*(long)soef[0]+ - (long)ssnd[1]*(long)soef[1]+ - (long)ssnd[2]*(long)soef[2]+ - (long)ssnd[3]*(long)soef[3],ivolsc>>15); - ivolsc += ivolsci; ispos += isinc; lptr += 2; nsamp--; - } while (nsamp); -#else - - //c = &coef[l]; - //h = &ssnd[u>>LSAMPREC] - // c[3] c[2] c[1] c[0] - //*h[3] *h[2] *h[1] *h[0] - //+p[3] +p[2] +p[1] +p[0] = s1 - if (cputype&(1<<23)) //MMX - { - _asm - { - push ebx - push esi - push edi - push ebp - mov esi, ispos - mov edi, lptr - mov ecx, nsamp - lea edi, [edi+ecx*8] - neg ecx - mov edx, dasnd - mov ebx, isinc - movd mm2, ivolsc - movd mm3, ivolsci - - test cputype, 1 shl 22 - mov ebp, coefilt - jnz short srndmmp - - mov eax, 0xffff0000 - movd mm7, eax - srndmmx:mov eax, esi ;MMX loop begins here - shr esi, LSAMPREC - movq mm0, [edx+esi*2] - lea esi, [eax+ebx] - and eax, (1< 1) - *(long *)(dasnd+(numsamps<<1) ) = *(long *)(dasnd+(repstart<<1) ); - *(long *)(dasnd+(numsamps<<1)+4) = *(long *)(dasnd+(repstart<<1)+4); - - while (i-isinc >= (numsamps<GetStatus(&u); if (!(u&DSBSTATUS_LOOPING)) return; - if (streambuf->GetCurrentPosition(&playcurs,&writcurs) != DS_OK) return; - leng = ((playcurs-oplaycurs)&(SNDSTREAMSIZ-1)); if (leng < minleng) return; - i = (oplaycurs&(SNDSTREAMSIZ-1)); - if (i < ((playcurs-1)&(SNDSTREAMSIZ-1))) - memset(&lsnd[i>>1],0,leng<<1); - else - { - memset(&lsnd[i>>1],0,((-oplaycurs)&(SNDSTREAMSIZ-1))<<1); - memset(lsnd,0,(playcurs&(SNDSTREAMSIZ-1))<<1); - } - - if (!numrendersnd) - { - streambuf->Lock(i,leng,&w[0],&l[0],&w[1],&l[1],0); - if (w[0]) memset(w[0],(bytespersample-2)&128,l[0]); - if (w[1]) memset(w[1],(bytespersample-2)&128,l[1]); - streambuf->Unlock(w[0],l[0],w[1],l[1]); - } - else - { - streambuf->Lock(i,leng,&w[0],&l[0],&w[1],&l[1],0); - - lptr[0] = &lsnd[i>>1]; lptr[1] = lsnd; - for(j=numrendersnd-1;j>=0;j--) - { - if (rendersnd[j].flags&KSND_MOVE) rendersnd[j].p = *rendersnd[j].ptr; //Get new 3D position - if (rendersnd[j].flags&KSND_3D) - { - n = (signed long)(leng>>gshiftval); - - float f, g, h; - f = (rendersnd[j].p.x-audiopos.x)*(rendersnd[j].p.x-audiopos.x)+(rendersnd[j].p.y-audiopos.y)*(rendersnd[j].p.y-audiopos.y)+(rendersnd[j].p.z-audiopos.z)*(rendersnd[j].p.z-audiopos.z); - g = (rendersnd[j].p.x-audiopos.x)*audiostr.x+(rendersnd[j].p.y-audiopos.y)*audiostr.y+(rendersnd[j].p.z-audiopos.z)*audiostr.z; - if (f <= SNDMINDIST*SNDMINDIST) { f = SNDMINDIST; h = (float)rendersnd[j].ivolsc; } else { f = sqrt(f); h = ((float)rendersnd[j].ivolsc)*SNDMINDIST/f; } - g /= f; //g=-1:pure left, g=0:center, g=1:pure right - //Should use exponential scaling to keep volume constant! - volsci0 = (long)((1.f-max(g*VOLSEPARATION,0))*h); - volsci1 = (long)((1.f+min(g*VOLSEPARATION,0))*h); - volsci0 = (volsci0-rendersnd[j].ivolsc0)/n; - volsci1 = (volsci1-rendersnd[j].ivolsc1)/n; - - //ispos? = ispos + (f voxels)*(.00025sec/voxel) * (isinc*samplerate subsamples/sec); - m = rendersnd[j].isinc*samplerate; - k = rendersnd[j].isinc*n + rendersnd[j].ispos; - h = max((f-SNDMINDIST)+g*(EARSEPARATION*.5f),0); nsinc0 = k - mulshr16((long)(h*(65536.f/SNDSPEED)),m); - h = max((f-SNDMINDIST)-g*(EARSEPARATION*.5f),0); nsinc1 = k - mulshr16((long)(h*(65536.f/SNDSPEED)),m); - nsinc0 = (nsinc0-rendersnd[j].ispos0)/n; - nsinc1 = (nsinc1-rendersnd[j].ispos1)/n; - } - else - { - nsinc0 = rendersnd[j].isinc; - nsinc1 = rendersnd[j].isinc; - volsci0 = 0; - volsci1 = 0; - } - if (rendersnd[j].flags&KSND_LOOPFADE) - { - n = -(signed long)(leng>>gshiftval); - volsci0 = rendersnd[j].ivolsc0/n; - volsci1 = rendersnd[j].ivolsc1/n; - } - for(m=0;m<2;m++) - if (w[m]) - { - k = (l[m]>>gshiftval); - if (!(rendersnd[j].flags&KSND_LOOP)) - { - rendersamps(rendersnd[j].ssnd,rendersnd[j].ispos0,nsinc0,rendersnd[j].ivolsc0,volsci0,lptr[m] ,k,rendersnd[j].coefilt); - rendersamps(rendersnd[j].ssnd,rendersnd[j].ispos1,nsinc1,rendersnd[j].ivolsc1,volsci1,lptr[m]+1,k,rendersnd[j].coefilt); - rendersnd[j].ispos += rendersnd[j].isinc*k; - rendersnd[j].ispos0 += nsinc0*k; rendersnd[j].ivolsc0 += volsci0*k; - rendersnd[j].ispos1 += nsinc1*k; rendersnd[j].ivolsc1 += volsci1*k; - - //Delete sound only when both L&R channels have played through all their samples - if (((rendersnd[j].ispos0>>LSAMPREC) >= (*(long *)(rendersnd[j].ssnd-8))) && - ((rendersnd[j].ispos1>>LSAMPREC) >= (*(long *)(rendersnd[j].ssnd-8)))) - { - (*(long *)(rendersnd[j].ssnd-16))--; numrendersnd--; - if (j != numrendersnd) rendersnd[j] = rendersnd[numrendersnd]; - break; - } - } - else - { - long numsamps, repleng; - numsamps = ((*(long *)(rendersnd[j].ssnd-8))<=numsamps;n-=repleng); - rendersampsloop(rendersnd[j].ssnd,n,nsinc0,rendersnd[j].ivolsc0,volsci0,lptr[m] ,k,rendersnd[j].coefilt); - for(n=rendersnd[j].ispos1;n>=numsamps;n-=repleng); - rendersampsloop(rendersnd[j].ssnd,n,nsinc1,rendersnd[j].ivolsc1,volsci1,lptr[m]+1,k,rendersnd[j].coefilt); - rendersnd[j].ispos += rendersnd[j].isinc*k; - rendersnd[j].ispos0 += nsinc0*k; - rendersnd[j].ispos1 += nsinc1*k; - rendersnd[j].ivolsc0 += volsci0*k; - rendersnd[j].ivolsc1 += volsci1*k; - - //Hack to keep sample pointers away from the limit... - while ((rendersnd[j].ispos0 >= numsamps) && (rendersnd[j].ispos1 >= numsamps)) - { - rendersnd[j].ispos -= repleng; - rendersnd[j].ispos0 -= repleng; rendersnd[j].ispos1 -= repleng; - } - } - } - if ((m >= 2) && (rendersnd[j].flags&KSND_LOOPFADE)) //Remove looping sound after fade-out - { - (*(long *)(rendersnd[j].ssnd-16))--; numrendersnd--; - if (j != numrendersnd) rendersnd[j] = rendersnd[numrendersnd]; - } - if (cputype&(1<<23)) _asm emms //MMX - } - for(m=0;m<2;m++) if (w[m]) audclipcopy(lptr[m],(short *)w[m],l[m]>>gshiftval); - if (cputype&(1<<23)) _asm emms //MMX - streambuf->Unlock(w[0],l[0],w[1],l[1]); - } - - oplaycurs = playcurs; -} - -#if (USETHREADS != 0) -static void kensoundthread (void *_) -{ - while (!quitprogram) - { - ENTERMUTX; - kensoundbreath(SNDSTREAMSIZ>>1); //WARNING: Don't call breath() here - WaitForSingleObject will fail :/ - LEAVEMUTX; - Sleep(USETHREADS); - } - quitprogram = 2; -} -#endif - - //Returns pointer to sound data; loads file if not already loaded. -long audgetfilebufptr (const char *filnam) -{ - WAVEFORMATEX wft; - long i, j, leng, hashind, newsnd, *lptr, repstart; - char tempbuf[12], *fptr; -#ifndef USEKZ - FILE *fil; -#endif - - if (audhashbuf) - { - for(i=audhashead[audcalchash(filnam)];i>=0;i=(*(long *)&audhashbuf[i])) - if (!filnamcmp(filnam,&audhashbuf[i+12])) return(*(long *)&audhashbuf[i+8]); - } - - //Load WAV file here! - repstart = 0x80000000; - if (filnam[0] == '<') //Sound is in memory! (KSND_MEM flag) - { - unsigned long u; //Filename is in weird hex format - for(i=1,u=0;i<9;i++) u = (u<<4)+(filnam[i]&15); - fptr = (char *)u; - - memcpy(tempbuf,fptr,12); fptr += 12; - if (*(long *)&tempbuf[0] != 0x46464952) return(0); //RIFF - if (*(long *)&tempbuf[8] != 0x45564157) return(0); //WAVE - for(j=16;j;j--) - { - memcpy(tempbuf,fptr,8); fptr += 8; i = *(long *)&tempbuf[0]; leng = *(long *)&tempbuf[4]; - if (i == 0x61746164) break; //data - if (i == 0x20746d66) //fmt - { - memcpy(&wft,fptr,16); fptr += 16; - if ((wft.wFormatTag != WAVE_FORMAT_PCM) || (wft.nChannels != 1)) return(0); - if (leng == 20) { memcpy(&repstart,fptr,4); fptr += 4; } - else if (leng > 16) fptr += ((leng-16+1)&~1); - continue; - } - fptr += ((leng+1)&~1); - //if (fptr > ?eof?) return(0); //corrupt WAV files in memory aren't detected :/ - } - if ((!j) || (!leng)) return(0); - } - else - { -#ifndef USEKZ - if (!(fil = fopen(filnam,"rb"))) return(0); - fread(tempbuf,12,1,fil); - if (*(long *)&tempbuf[0] != 0x46464952) { fclose(fil); return(0); } //RIFF - if (*(long *)&tempbuf[8] != 0x45564157) { fclose(fil); return(0); } //WAVE - for(j=16;j;j--) - { - fread(&tempbuf,8,1,fil); i = *(long *)&tempbuf[0]; leng = *(long *)&tempbuf[4]; - if (i == 0x61746164) break; //data - if (i == 0x20746d66) //fmt - { - fread(&wft,16,1,fil); - if ((wft.wFormatTag != WAVE_FORMAT_PCM) || (wft.nChannels != 1)) { fclose(fil); return(0); } - if (leng == 20) fread(&repstart,4,1,fil); - else if (leng > 16) fseek(fil,(leng-16+1)&~1,SEEK_CUR); - continue; - } - fseek(fil,(leng+1)&~1,SEEK_CUR); - if (feof(fil)) { fclose(fil); return(0); } - } - if ((!j) || (!leng)) { fclose(fil); return(0); } -#else - if (!kzopen(filnam)) return(0); - kzread(tempbuf,12); - if (*(long *)&tempbuf[0] != 0x46464952) { kzclose(); return(0); } //RIFF - if (*(long *)&tempbuf[8] != 0x45564157) { kzclose(); return(0); } //WAVE - for(j=16;j;j--) - { - kzread(tempbuf,8); i = *(long *)&tempbuf[0]; leng = *(long *)&tempbuf[4]; - if (i == 0x61746164) break; //data - if (i == 0x20746d66) //fmt - { - kzread(&wft,16); - if ((wft.wFormatTag != WAVE_FORMAT_PCM) || (wft.nChannels != 1)) { kzclose(); return(0); } - if (leng == 20) kzread(&repstart,4); - else if (leng > 16) kzseek((leng-16+1)&~1,SEEK_CUR); - continue; - } - kzseek((leng+1)&~1,SEEK_CUR); - if (kzeof()) { kzclose(); return(0); } - } - if ((!j) || (!leng)) { kzclose(); return(0); } -#endif - } - - if (wft.wBitsPerSample == 16) i = leng; else i = (leng<<1); //Convert 8-bit to 16-bit - - if (filnam[0] == '<') //Sound is in memory! (KSND_MEM flag) - { - if (!(newsnd = (long)malloc(16+i+8))) return(0); - memcpy((void *)(newsnd+16),fptr,leng); - } - else - { -#ifndef USEKZ - if (!(newsnd = (long)malloc(16+i+8))) { fclose(fil); return(0); } - fread((void *)(newsnd+16),leng,1,fil); - fclose(fil); -#else - if (!(newsnd = (long)malloc(16+i+8))) { kzclose(); return(0); } - kzread((void *)(newsnd+16),leng); - kzclose(); -#endif - } - - if (wft.wBitsPerSample == 8) //Convert 8-bit to 16-bit - { - j = newsnd+16; - for(i=leng-1;i>=0;i--) (*(short *)((i<<1)+j)) = (((short)((*(signed char *)(i+j))-128))<<8); - wft.wBitsPerSample = 16; leng <<= 1; - } - *(long *)(newsnd) = 0; //Allocation count - *(long *)(newsnd+4) = repstart; //Loop repeat start sample - *(long *)(newsnd+8) = (leng>>1); // /((wft.wBitsPerSample>>3)*wft.nChannels); //numsamples - *(float *)(newsnd+12) = (float)(wft.nSamplesPerSec<GetStatus(&u); if (!(u&DSBSTATUS_LOOPING)) { LEAVEMUTX; return; } - - if (flags&KSND_MEM) - { - char tempbuf[10]; //Convert to ASCII string so filnamcmp()&audcalchash() works right - tempbuf[9] = 0; u = (unsigned long)filnam; - for(i=8;i>0;i--) { tempbuf[i] = (u&15)+64; u >>= 4; } - tempbuf[0] = '<'; //This invalid filename char tells audgetfilebufptr it's KSND_MEM - if (!(newsnd = audgetfilebufptr(tempbuf))) { LEAVEMUTX; return; } - } - else - { - if (!(newsnd = audgetfilebufptr(filnam))) { LEAVEMUTX; return; } - } - newsnd += 16; - - ispos = 0; isinc = (long)((*(float *)(newsnd-4))*frqmul*rsamplerate); - ivolsc = (volperc<<15)/100; if (ivolsc >= 32768) ivolsc = 32767; ivolsc <<= 16; - - if (!pos) flags &= ~(KSND_3D|KSND_MOVE); //null pointers not allowed for 3D sound - if (flags&KSND_MOVE) flags |= KSND_3D; //moving sound must be 3D sound - if ((flags&KSND_LOOP) && ((*(long *)(newsnd-12)) == 0x80000000)) - flags &= ~KSND_LOOP; //WAV must support looping to allow looping - - if (!(flags&KSND_LOPASS)) coefilt = coef; else coefilt = coeflopass; - - if (flags&KSND_3D) - { - f = (((point3d *)pos)->x-audiopos.x)*(((point3d *)pos)->x-audiopos.x)+(((point3d *)pos)->y-audiopos.y)*(((point3d *)pos)->y-audiopos.y)+(((point3d *)pos)->z-audiopos.z)*(((point3d *)pos)->z-audiopos.z); - g = (((point3d *)pos)->x-audiopos.x)*audiostr.x+(((point3d *)pos)->y-audiopos.y)*audiostr.y+(((point3d *)pos)->z-audiopos.z)*audiostr.z; - if (f <= SNDMINDIST*SNDMINDIST) { f = SNDMINDIST; h = (float)ivolsc; } else { f = sqrt(f); h = ((float)ivolsc)*SNDMINDIST/f; } - g /= f; //g=-1:pure left, g=0:center, g=1:pure right - //Should use exponential scaling to keep volume constant! - ivolsc0 = (long)((1.f-max(g*VOLSEPARATION,0))*h); - ivolsc1 = (long)((1.f+min(g*VOLSEPARATION,0))*h); - //ispos? = ispos + (f voxels)*(.00025sec/voxel) * (isinc*samplerate subsamples/sec); - m = isinc*samplerate; - h = max((f-SNDMINDIST)+g*(EARSEPARATION*.5f),0); ispos0 = -mulshr16((long)(h*(65536.f/SNDSPEED)),m); - h = max((f-SNDMINDIST)-g*(EARSEPARATION*.5f),0); ispos1 = -mulshr16((long)(h*(65536.f/SNDSPEED)),m); - } - else { ispos0 = ispos1 = 0; ivolsc0 = ivolsc1 = ivolsc; } - - kensoundbreath(SNDSTREAMSIZ>>1); //Not necessary, but for good luck - if (streambuf->GetCurrentPosition(&playcurs,&writcurs) != DS_OK) { LEAVEMUTX; return; } - //If you use playcurs instead of writcurs, beginning of sound gets cut off :/ - //on WinXP: ((writcurs-playcurs)&(SNDSTREAMSIZ-1)) ranges from 6880 to 8820 (step 4) - i = (writcurs&(SNDSTREAMSIZ-1)); - if (streambuf->Lock(i,(oplaycurs-i)&(SNDSTREAMSIZ-1),&w[0],&l[0],&w[1],&l[1],0) != DS_OK) { LEAVEMUTX; return; } - lptr[0] = &lsnd[i>>1]; lptr[1] = lsnd; - for(m=0;m<2;m++) - if (w[m]) - { - j = (l[m]>>gshiftval); - if (!(flags&KSND_LOOP)) - { - rendersamps(newsnd,ispos0,isinc,ivolsc0,0,lptr[m] ,j,coefilt); - rendersamps(newsnd,ispos1,isinc,ivolsc1,0,lptr[m]+1,j,coefilt); - j *= isinc; ispos += j; ispos0 += j; ispos1 += j; - } - else - { - long numsamps, repleng, n; - numsamps = ((*(long *)(newsnd-8))<=numsamps;n-=repleng); - rendersampsloop(newsnd,n,isinc,ivolsc0,0,lptr[m] ,j,coefilt); - for(n=ispos1;n>=numsamps;n-=repleng); - rendersampsloop(newsnd,n,isinc,ivolsc1,0,lptr[m]+1,j,coefilt); - j *= isinc; ispos += j; ispos0 += j; ispos1 += j; - - //Hack to keep sample pointers away from the limit... - while ((ispos0 >= numsamps) && (ispos1 >= numsamps)) - { ispos -= repleng; ispos0 -= repleng; ispos1 -= repleng; } - } - } - for(m=0;m<2;m++) if (w[m]) audclipcopy(lptr[m],(short *)w[m],l[m]>>gshiftval); - if (cputype&(1<<23)) _asm emms //MMX - streambuf->Unlock(w[0],l[0],w[1],l[1]); - - //Save params to continue playing later (when both L&R channels haven't played through) - numsamps = *(long *)(newsnd-8); - if ((((ispos0>>LSAMPREC) < numsamps) || ((ispos1>>LSAMPREC) < numsamps) || (flags&KSND_LOOP)) && (numrendersnd < MAXPLAYINGSNDS)) - { - rendersnd[numrendersnd].ptr = (point3d *)pos; - if (flags&KSND_3D) rendersnd[numrendersnd].p = *((point3d *)pos); - else { rendersnd[numrendersnd].p.x = rendersnd[numrendersnd].p.y = rendersnd[numrendersnd].p.z = 0; } - rendersnd[numrendersnd].flags = flags; - rendersnd[numrendersnd].ssnd = newsnd; - rendersnd[numrendersnd].ispos = ispos; - rendersnd[numrendersnd].ispos0 = ispos0; - rendersnd[numrendersnd].ispos1 = ispos1; - rendersnd[numrendersnd].isinc = isinc; - rendersnd[numrendersnd].ivolsc = ivolsc; - rendersnd[numrendersnd].ivolsc0 = ivolsc0; - rendersnd[numrendersnd].ivolsc1 = ivolsc1; - rendersnd[numrendersnd].coefilt = coefilt; - numrendersnd++; - (*(long *)(newsnd-16))++; - } - - LEAVEMUTX; -} - - //Use this function to update a pointer location (if you need to move things around in memory) - //special cases: if (optr== 0) changes all pointers - // if (nptr== 0) changes KSND_MOVE to KSND_3D - // if (nptr==-1) changes KSND_MOVE to KSND_3D and stops sound (using KSND_LOOPFADE) - //examples: playsoundupdate(&spr[delete_me].p,&spr[--numspr].p); //update pointer location - // playsoundupdate(&spr[just_before_respawn],0); //stop position updates from pointer - // playsoundupdate(&my_looping_sound,(point3d *)-1); //turn off a looping sound - // playsoundupdate(0,0); //stop all position updates - // playsoundupdate(0,(point3d *)-1); //turn off all sounds -void playsoundupdate (void *optr, void *nptr) -{ - long i; - - if (!dsound) return; - ENTERMUTX; - for(i=numrendersnd-1;i>=0;i--) - { - if ((rendersnd[i].ptr != (point3d *)optr) && (optr)) continue; - if (((long)nptr) == -2) { rendersnd[i].flags |= KSND_LOPASS; rendersnd[i].coefilt = coeflopass; continue; } - if (((long)nptr) == -3) { rendersnd[i].flags &= ~KSND_LOPASS; rendersnd[i].coefilt = coef; continue; } - rendersnd[i].ptr = (point3d *)nptr; - if (!((((long)nptr)+1)&~1)) - { - rendersnd[i].flags &= ~KSND_MOVE; //nptr == {0,-1} - if (nptr) rendersnd[i].flags |= KSND_LOOPFADE; //nptr == {-1} - } - } - LEAVEMUTX; -} - -#endif -// Kensound code ends --------------------------------------------------------- - -// DirectSound variables & code ---------------------------------------------- - -#ifdef DSOUNDINITCOM -static HRESULT coinit; -#endif - -#define MAXSOUNDS 256 -LPDIRECTSOUNDBUFFER dsprim = 0; -#if (USEKENSOUND == 2) -LPDIRECTSOUNDBUFFER dsbuf[MAXSOUNDS]; -LPDIRECTSOUND3DBUFFER ds3dbuf[MAXSOUNDS]; -LPDIRECTSOUND3DLISTENER ds3dlis = 0; -static long sndindex = -1; -#endif -static long globvolume = 100; - - //0=-10000,1-100=CINT(log10(z/100)*1000) -signed short volperc2db100[104] = -{ - -10000,-2000,-1699,-1523,-1398,-1301,-1222,-1155,-1097,-1046, // 0 to 9 - -1000, -959, -921, -886, -854, -824, -796, -770, -745, -721, //10 to 19 - -699, -678, -658, -638, -620, -602, -585, -569, -553, -538, //20 to 29 - -523, -509, -495, -481, -469, -456, -444, -432, -420, -409, //30 to 39 - -398, -387, -377, -367, -357, -347, -337, -328, -319, -310, //40 to 49 - -301, -292, -284, -276, -268, -260, -252, -244, -237, -229, //50 to 59 - -222, -215, -208, -201, -194, -187, -180, -174, -167, -161, //60 to 69 - -155, -149, -143, -137, -131, -125, -119, -114, -108, -102, //70 to 79 - -97, -92, -86, -81, -76, -71, -66, -60, -56, -51, //80 to 89 - -46, -41, -36, -32, -27, -22, -18, -13, -9, -4, //90 to 99 - 0, //100 -}; - -void setvolume (long percentmax) -{ - if (!dsprim) return; - globvolume = min(max(percentmax,0),100); - dsprim->SetVolume(volperc2db100[globvolume]); -} - -void uninitdirectsound () -{ - long i; - - if (!dsound) return; -#if (USEKENSOUND == 1) - kensoundclose(); -#endif - -#if (USEKENSOUND == 2) - for(i=MAXSOUNDS-1;i>=0;i--) - if (ds3dbuf[i]) { ds3dbuf[i]->Release(); ds3dbuf[i] = 0; } - if (ds3dlis) { ds3dlis->Release(); ds3dlis = 0; } - for(i=MAXSOUNDS-1;i>=0;i--) - if (dsbuf[i]) { dsbuf[i]->Release(); dsbuf[i] = 0; } -#endif - dsound->Release(); dsound = 0; -} - -void initdirectsound () -{ - DSBUFFERDESC dsbdesc; - long i; - - if (dsound) uninitdirectsound(); - -#if (USEKENSOUND == 2) - for(i=0;iInitialize(NULL); - //dsrval = IDirectSound_Initialize(dsound,NULL); - //(dsound)->Release(lpds); - if (dsrval != S_OK) { dsound = NULL; return; } - } - } -#else - if (DirectSoundCreate(0,&dsound,0) != DS_OK) { MessageBox(ghwnd,"DirectSoundCreate","ERROR",MB_OK); exit(0); } -#endif - if (dsound->SetCooperativeLevel(ghwnd,DSSCL_PRIORITY) != DS_OK) { MessageBox(ghwnd,"SetCooperativeLevel","ERROR",MB_OK); exit(0); } - - //Create primary buffer - dsbdesc.dwSize = sizeof(DSBUFFERDESC); - dsbdesc.dwFlags = DSBCAPS_PRIMARYBUFFER; -#if (USEKENSOUND == 2) - dsbdesc.dwFlags |= DSBCAPS_CTRL3D|DSBCAPS_CTRLVOLUME; -#endif - dsbdesc.dwBufferBytes = 0; //0 for primary - dsbdesc.dwReserved = 0; - dsbdesc.lpwfxFormat = 0; //0 for primary - if (dsound->CreateSoundBuffer(&dsbdesc,&dsprim,0) < 0) - { dsound->Release(); MessageBox(ghwnd,"CreateSoundBuffer (primary) failed","ERROR",MB_OK); exit(0); } - - dsprim->Play(0,0,DSBPLAY_LOOPING); //Force mixer to always be on - -#if (USEKENSOUND == 2) - //Default listener orientation: - // <1,0,0>: right - // <0,1,0>: up - // <0,0,1>: front - //Initialize 3D sound - if (dsprim->QueryInterface(IID_IDirectSound3DListener,(void **)&ds3dlis) != S_OK) - { dsound->Release(); MessageBox(ghwnd,"Query...Listener failed","ERROR",MB_OK); exit(0); } - ds3dlis->SetDistanceFactor(.03,DS3D_DEFERRED); //1 (meters/unit) - ds3dlis->SetRolloffFactor(.03,DS3D_DEFERRED); //1 - ds3dlis->SetDopplerFactor(1,DS3D_DEFERRED); //1 - ds3dlis->SetPosition(0,0,0,DS3D_DEFERRED); //0,0,0 - ds3dlis->SetVelocity(0,0,0,DS3D_DEFERRED); //0,0,0 - ds3dlis->SetOrientation(0,0,1,0,1,0,DS3D_DEFERRED); //0,0,1,0,1,0 - ds3dlis->CommitDeferredSettings(); -#endif - - if (globvolume != 100) dsprim->SetVolume(globvolume); - -#if (USEKENSOUND == 1) - kensoundinit(dsound,44100,2,2); //last line -#endif -} - -#if (USEKENSOUND == 2) - -#define MINSNDLENG 4096 //is 1764 min size? too bad it fails sometimes :/ 1764*25 = 44100 -long loadwav (LPDIRECTSOUNDBUFFER *dabuf, const char *fnam, float freqmul, unsigned long daflags) -{ - WAVEFORMATEX wft; - DSBUFFERDESC bufdesc; - void *w0, *w1; - unsigned long l0, l1, leng; - char tempbuf[12]; - -#ifndef USEKZ - FILE *fil; - if (!(fil = fopen(fnam,"rb"))) return(0); - fread(tempbuf,12,1,fil); - if (*(long *)&tempbuf[0] != 0x46464952) { fclose(fil); return(0); } //RIFF - if (*(long *)&tempbuf[8] != 0x45564157) { fclose(fil); return(0); } //WAVE - for(l1=16;l1;l1--) - { - fread(&tempbuf,8,1,fil); l0 = *(long *)&tempbuf[0]; leng = *(long *)&tempbuf[4]; - if (l0 == 0x61746164) break; //data - if (l0 == 0x20746d66) //fmt - { - fread(&wft,16,1,fil); - //if ((wft.wFormatTag != WAVE_FORMAT_PCM) || (wft.nChannels != 1)) { fclose(fil); return(0); } - if (leng > 16) fseek(fil,(leng-16+1)&~1,SEEK_CUR); - continue; - } - fseek(fil,(leng+1)&~1,SEEK_CUR); - if (feof(fil)) { fclose(fil); return(0); } - } - if (!l1) { fclose(fil); return(0); } -#else - if (!kzopen(fnam)) return(0); - kzread(tempbuf,12); - if (*(long *)&tempbuf[0] != 0x46464952) { kzclose(); return(0); } //RIFF - if (*(long *)&tempbuf[8] != 0x45564157) { kzclose(); return(0); } //WAVE - for(l1=16;l1;l1--) - { - kzread(tempbuf,8); l0 = *(long *)&tempbuf[0]; leng = *(long *)&tempbuf[4]; - if (l0 == 0x61746164) break; //data - if (l0 == 0x20746d66) //fmt - { - kzread(&wft,16); - //if ((wft.wFormatTag != WAVE_FORMAT_PCM) || (wft.nChannels != 1)) { kzclose(); return(0); } - if (leng > 16) kzseek((leng-16+1)&~1,SEEK_CUR); - continue; - } - kzseek((leng+1)&~1,SEEK_CUR); - if (kzeof()) { kzclose(); return(0); } - } - if (!l1) { kzclose(); return(0); } -#endif - - if (*(long *)&freqmul != 0x3f800000) - { - wft.nSamplesPerSec = (long)((float)wft.nSamplesPerSec * freqmul); - wft.nAvgBytesPerSec = wft.nSamplesPerSec * wft.nBlockAlign; - } - wft.cbSize = 0; - - bufdesc.dwSize = sizeof(DSBUFFERDESC); - bufdesc.dwFlags = daflags; - bufdesc.dwBufferBytes = max(leng,MINSNDLENG); - bufdesc.dwReserved = 0; - bufdesc.lpwfxFormat = &wft; - //bufdesc.guid3DAlgorithm = GUID_NULL; -#ifndef USEKZ - if (dsound->CreateSoundBuffer(&bufdesc,dabuf,0) != DS_OK) - { fclose(fil); return(0); } - //write wave data to directsound buffer you just created - if (((*dabuf)->Lock(0,leng,&w0,&l0,&w1,&l1,0)) == DSERR_BUFFERLOST) { fclose(fil); return(0); } - if (w0) fread(w0,l0,1,fil); - if (w1) fread(w1,l1,1,fil); - (*dabuf)->Unlock(w0,l0,w1,l1); - fclose(fil); -#else - if (dsound->CreateSoundBuffer(&bufdesc,dabuf,0) != DS_OK) - { kzclose(); return(0); } - //write wave data to directsound buffer you just created - (*dabuf)->Lock(0,leng,&w0,&l0,&w1,&l1,0); - if (w0) kzread(w0,l0); - if (w1) kzread(w1,l1); - (*dabuf)->Unlock(w0,l0,w1,l1); - kzclose(); -#endif - - //This hack is because DSOUND seems to have problems with very short secondary buffers! - if (leng < MINSNDLENG) - { - if (((*dabuf)->Lock(leng,MINSNDLENG-leng,&w0,&l0,&w1,&l1,0)) == DSERR_BUFFERLOST) return(0); - if (w0) memset(w0,(wft.wBitsPerSample==8)<<7,l0); - if (w1) memset(w1,(wft.wBitsPerSample==8)<<7,l1); - (*dabuf)->Unlock(w0,l0,w1,l1); - } - - return(1); -} - -void setears3d (float iposx, float iposy, float iposz, - float iforx, float ifory, float iforz, - float iheix, float iheiy, float iheiz) -{ - if (!ds3dlis) return; - ds3dlis->SetPosition(iposx,iposy,iposz,DS3D_DEFERRED); - ds3dlis->SetOrientation(iforx,ifory,iforz,iheix,iheiy,iheiz,DS3D_DEFERRED); //0,0,1,0,1,0 - ds3dlis->CommitDeferredSettings(); -} - -long reallyuglyandslowhack4sound () -{ - long i; - unsigned long u; - - sndindex++; - - i = (sndindex&(MAXSOUNDS-1)); - if (ds3dbuf[i]) { ds3dbuf[i]->Release(); ds3dbuf[i] = 0; } - if (dsbuf[i]) { dsbuf[i]->Release(); dsbuf[i] = 0; } - - for(i=0;iGetStatus(&u); - if (!(u&DSBSTATUS_PLAYING)) - { - if (ds3dbuf[i]) { ds3dbuf[i]->Release(); ds3dbuf[i] = 0; } - if (dsbuf[i]) { dsbuf[i]->Release(); dsbuf[i] = 0; } - } - } - return(sndindex&(MAXSOUNDS-1)); -} - -void playsound (const char *filnam, long volperc, float freqmul) -{ - unsigned long u, cnt; - long i; - - if (!dsound) return; - i = reallyuglyandslowhack4sound(); - - if ((!dsound) || ((unsigned long)i >= MAXSOUNDS)) return; - for(cnt=2;cnt;cnt--) - { - if (!dsbuf[i]) if (!loadwav(&dsbuf[i],filnam,freqmul,(((volperc-100)>>31)&DSBCAPS_CTRLVOLUME)|DSBCAPS_STATIC)) return; - dsbuf[i]->GetStatus(&u); if (u&DSBSTATUS_PLAYING) return; - if (volperc < 100) dsbuf[i]->SetVolume(volperc2db100[max(volperc,0)]); - dsbuf[i]->SetCurrentPosition(0); - if (dsbuf[i]->Play(0,0,0) != DSERR_BUFFERLOST) return; - dsbuf[i]->Release(); dsbuf[i] = 0; - } -} - -void playsound (const char *filnam, long volperc, float freqmul, void *pos, long flags) -{ - unsigned long u, cnt; - long i; - - if (!dsound) return; - if (!(flags&1)) { playsound(filnam,volperc,freqmul); return; } - - i = reallyuglyandslowhack4sound(); - - if ((!dsound) || ((unsigned long)i >= MAXSOUNDS)) return; - for(cnt=2;cnt;cnt--) - { - if (!dsbuf[i]) - { - if (!loadwav(&dsbuf[i],filnam,freqmul,(((volperc-100)>>31)&DSBCAPS_CTRLVOLUME)| - DSBCAPS_CTRL3D|DSBCAPS_STATIC|DSBCAPS_MUTE3DATMAXDISTANCE)) return; - if (ds3dbuf[i]) { ds3dbuf[i]->Release(); ds3dbuf[i] = 0; } - dsbuf[i]->QueryInterface(IID_IDirectSound3DBuffer,(void **)&ds3dbuf[i]); - ds3dbuf[i]->SetMode(DS3DMODE_NORMAL,DS3D_DEFERRED); //DS3DMODE_NORMAL - //ds3dbuf[i]->SetMaxDistance(1000000000,DS3D_DEFERRED); //1000000000 - //ds3dbuf[i]->SetMinDistance(1,DS3D_DEFERRED); //1 - ds3dbuf[i]->SetPosition(((point3d *)pos)->x,((point3d *)pos)->y,((point3d *)pos)->z,DS3D_DEFERRED); //0,0,0 - //ds3dbuf[i]->SetVelocity(0,0,0,DS3D_DEFERRED); //0,0,0 - //ds3dbuf[i]->SetConeAngles(0,360,DS3D_DEFERRED); //0,360 - //ds3dbuf[i]->SetConeOrientation(0,0,0,DS3D_DEFERRED); //0,0,0 - //ds3dbuf[i]->SetConeOutsideVolume(DSBVOLUME_MAX,DS3D_DEFERRED); //DSBVOLUME_MAX - ds3dlis->CommitDeferredSettings(); - } - else - { - ds3dbuf[i]->SetPosition(((point3d *)pos)->x,((point3d *)pos)->y,((point3d *)pos)->z,DS3D_IMMEDIATE); - } - dsbuf[i]->GetStatus(&u); if (u&DSBSTATUS_PLAYING) return; - if (volperc < 100) dsbuf[i]->SetVolume(volperc2db100[max(volperc,0)]); - dsbuf[i]->SetCurrentPosition(0); - if (dsbuf[i]->Play(0,0,0) != DSERR_BUFFERLOST) return; - if (ds3dbuf[i]) { ds3dbuf[i]->Release(); ds3dbuf[i] = 0; } - if (dsbuf[i]) { dsbuf[i]->Release(); dsbuf[i] = 0; } - } -} - -void playsoundupdate (void *oposptr, void *nposptr) -{ - //if (!nptr) follow = 0 -} - -#endif -#endif - -//Quitting routines ---------------------------------------------------------- - -long (*catchwmclose)() = 0; -void quitloop () { PostMessage(ghwnd,WM_CLOSE,0,0); } - -void evilquit (const char *str) //Evil because this function makes awful assumptions!!! -{ -#ifndef NODRAW - stopdirectdraw(); - ddflip2gdi(); -#endif - if (str) MessageBox(ghwnd,str,"fatal error!",MB_OK); -#ifndef NOINPUT - uninitmouse(); - uninitkeyboard(); - uninitdirectinput(); -#endif -#ifndef NOSOUND - uninitdirectsound(); -#endif -#ifndef NODRAW - uninitdirectdraw(); -#endif - uninitapp(); - ExitProcess(0); -} - -//GENERAL WINDOWS CODE------------------------------------------------------------------- - -void setalwaysactive (long active) { alwaysactive = active; } - -#ifndef NODRAW -long canrender () { return(ActiveApp); } -#endif - -#ifndef NOINPUT -void setacquire (long mouse, long kbd) -{ - if (mouse_acquire != mouse) - { - if (ActiveApp && gpMouse) { if (mouse) { gpMouse->Acquire(); gbstatus = 0; } else gpMouse->Unacquire(); } - mouse_acquire = mouse; - } - if (kbd_acquire != kbd) - { - if (ActiveApp && gpKeyboard) { if (kbd) { gpKeyboard->Acquire(); shkeystatus = 0; } else gpKeyboard->Unacquire(); } - kbd_acquire = kbd; - } -} -void setmouseout (void (*in)(long,long), long x, long y) -{ - if (fullscreen) return; - setmousein = in; - setacquire(0, kbd_acquire); - - POINT topLeft; - topLeft.x = 0; topLeft.y = 0; - ClientToScreen(ghwnd, &topLeft); - SetCursorPos(topLeft.x + x, topLeft.y + y); -} - - //Use fancy clipper to determine if mouse cursor (x,y) is outside the window - //Note: x,y is relative to top-left corner of ghwnd -long ismouseout (long x, long y) -{ - if (fullscreen) return(0); -#ifndef NO_CLIPPER - //unsigned long siz; - - //ddclip->GetClipList(0,0,&siz); - //if (siz > ddcliprdbytes) - //{ - // ddcliprdbytes = siz; - // ddcliprd = (RGNDATA *)realloc(ddcliprd,siz); - //} -#ifndef NODRAW - if (ddcliprd) - { - POINT abspos; - RECT *r; - long j; - //ddclip->GetClipList(0,ddcliprd,&siz); - - abspos.x = x; abspos.y = y; - ClientToScreen(ghwnd,&abspos); - - r = (RECT *)ddcliprd->Buffer; - for(j=0;j<(long)ddcliprd->rdh.nCount;j++) - { - if ((abspos.x >= r[j].left) && (abspos.x < r[j].right) && - (abspos.y >= r[j].top) && (abspos.y < r[j].bottom)) - return(0); - } - return(1); - } -#endif -#endif - return(((unsigned long)x >= (unsigned long)xres) || ((unsigned long)y >= (unsigned long)yres)); -} - -#endif - -long (CALLBACK *peekwindowproc)(HWND,UINT,WPARAM,LPARAM) = 0; -long CALLBACK WindowProc (HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - // mouse pos: - static long omx, omy; - long mx, my; - - if (peekwindowproc) { mx = peekwindowproc(hwnd,msg,wParam,lParam); if (mx >= 0) return(mx); } - switch (msg) - { - case WM_SYSCOMMAND: - if ((wParam == SC_KEYMENU) || (wParam == SC_HOTKEY)) return(0); - break; - case WM_ACTIVATEAPP: - ActiveApp = (BOOL)wParam; //!((BOOL)HIWORD(wParam)); - shkeystatus = 0; -#ifndef NOINPUT - gkillbstatus = 1; -#endif - break; - - case WM_ACTIVATE: - //ActiveApp = LOWORD(wParam); //((wParam&65535) != WA_INACTIVE); -#ifndef NOINPUT - if (gpMouse) { if (ActiveApp && mouse_acquire) { gpMouse->Acquire(); gbstatus = 0; } else gpMouse->Unacquire(); } - if (gpKeyboard) { if (ActiveApp && kbd_acquire) { gpKeyboard->Acquire(); shkeystatus = 0; } else gpKeyboard->Unacquire(); } -#endif -#ifndef NODRAW - if ((!fullscreen) && (ActiveApp) && (ddpal) && (ddsurf[0])) - { - if (ddsurf[0]->IsLost() == DDERR_SURFACELOST) ddsurf[0]->Restore(); - ddsurf[0]->SetPalette(ddpal); - updatepalette(0,256); - } - InvalidateRect(hwnd,0,1); -#endif - break; - case WM_PAINT: -#ifndef NODRAW - if (!fullscreen) nextpage(); -#endif - break; - - case WM_SIZE: - gncmdshow = wParam; - if (wParam == SIZE_MAXHIDE) - ActiveApp = 0; - else if (wParam == SIZE_MINIMIZED) - ActiveApp = 0; - else - { - ActiveApp = 1; -#ifndef NODRAW -#ifndef ZOOM_TEST - if ((!fullscreen) && (ddsurf[1])) - { - long oxres = xres, oyres = yres; - xres = LOWORD(lParam); yres = HIWORD(lParam); - - if (ddsurf[1]) { ddsurf[1]->Release(); ddsurf[1] = 0; } - - ddsd.dwSize = sizeof(ddsd); - ddsd.dwFlags = DDSD_WIDTH | DDSD_HEIGHT | DDSD_CAPS; - ddsd.ddsCaps.dwCaps = DDSCAPS_OFFSCREENPLAIN; - ddsd.dwWidth = xres; - ddsd.dwHeight = yres; - lpdd->CreateSurface(&ddsd,&ddsurf[1],0); - - if (ddrawemulbuf) - { - long i, x, y, ye, pw, pr; - - i = ((colbits+7)>>3)*xres; - if (i < ddrawemulbpl) - { - pw = pr = ((long)ddrawemulbuf); ye = min(yres,oyres); - for(y=1;y>3)+16); - if (!ddrawemulbuf) - { - xres = oxres; yres = oyres; //oops :/ - ddrawemulbuf = realloc(ddrawemulbuf,((xres*yres+7)&~7)*((colbits+7)>>3)+16); - i = ddrawemulbpl; - } - - if (i > ddrawemulbpl) - { - pw = yres*i + ((long)ddrawemulbuf); - pr = yres*ddrawemulbpl + ((long)ddrawemulbuf); - for(y=yres-1;y>=0;y--) - { - pw -= i; pr -= ddrawemulbpl; - for(x=i-1;x>=ddrawemulbpl;x--) *(char *)(pw+x) = 0; - for(;x>=0;x--) *(char *)(pw+x) = *(char *)(pr+x); - } - } - if (yres > oyres) memset((void *)(oyres*i+((long)ddrawemulbuf)),0,(yres-oyres)*i); - - ddrawemulbpl = i; - } - } -#endif -#endif - } -#ifndef NOINPUT - if (gpMouse) { if (ActiveApp && mouse_acquire) { gpMouse->Acquire(); gbstatus = 0; } else gpMouse->Unacquire(); } - if (gpKeyboard) { if (ActiveApp && kbd_acquire) { gpKeyboard->Acquire(); shkeystatus = 0; } else gpKeyboard->Unacquire(); } -#endif - break; - case WM_KEYDOWN: -#ifdef NOINPUT - keystatus[((lParam>>16)&127)+((lParam>>17)&128)] = 1; -#endif - case WM_SYSKEYDOWN: - if ((wParam&0xff) == 0xff) break; //Fixes SHIFT+[ext key] on XP - switch (lParam&0x17f0000) - { - case 0x02a0000: shkeystatus |= (1<<16); break; //0x2a - case 0x0360000: shkeystatus |= (1<<17); break; //0x36 - case 0x01d0000: shkeystatus |= (1<<18); break; //0x1d - case 0x11d0000: shkeystatus |= (1<<19); break; //0x9d - case 0x0380000: shkeystatus |= (1<<20); break; //0x38 - case 0x1380000: shkeystatus |= (1<<21); break; //0xb8 - default: - { - long i = ((keybufw2+1)&(KEYBUFSIZ-1)); - keybuf[keybufw2&(KEYBUFSIZ-1)] = (((lParam>>8)&0x7f00)+((lParam>>9)&0x8000))+shkeystatus; - if (i != keybufr) keybufw2 = i; //prevent fifo overlap - } - } - return(0); - case WM_KEYUP: -#ifdef NOINPUT - keystatus[((lParam>>16)&127)+((lParam>>17)&128)] = 0; -#endif - case WM_SYSKEYUP: - if ((wParam&0xff) == 0xff) break; //Fixes SHIFT+[ext key] on XP - switch (lParam&0x17f0000) - { - case 0x02a0000: shkeystatus &= ~(3<<16); break; //0x2a - case 0x0360000: shkeystatus &= ~(3<<16); break; //0x36 - case 0x01d0000: shkeystatus &= ~(1<<18); break; //0x1d - case 0x11d0000: shkeystatus &= ~(1<<19); break; //0x9d - case 0x0380000: shkeystatus &= ~(1<<20); break; //0x38 - case 0x1380000: shkeystatus &= ~(1<<21); break; //0xb8 - } - return(0); - case WM_CHAR: - if (keybufw2 != keybufr) //stick ASCII code in last FIFO value - keybuf[(keybufw2-1)&(KEYBUFSIZ-1)] |= (wParam&255); - return(0); - case WM_MOUSEWHEEL: - mx = (signed short)HIWORD(wParam); - if (mx > 0) ext_mbstatus[6] = 2; - else if (mx < 0) ext_mbstatus[7] = 2; - ext_mwheel = min(max(ext_mwheel+mx,(unsigned long)(1<<16)-(unsigned long)(1<<31)),(unsigned long)(1<<31)-(unsigned long)(1<<16)); - - break; -#ifndef NOINPUT - case WM_MOUSEMOVE: - mx = LOWORD(lParam); - my = HIWORD(lParam); - if (gpMouse && ActiveApp && setmousein) { - mouse_acquire = 1; - gpMouse->Acquire(); gbstatus = 0; - setmousein(mx, my); - setmousein = NULL; - } - break; -#endif - case WM_LBUTTONDOWN: if (!mouse_acquire) ext_mbstatus[0] = 1|2; break; - case WM_LBUTTONUP: if (!mouse_acquire) ext_mbstatus[0] &= ~2; break; - case WM_RBUTTONDOWN: if (!mouse_acquire) ext_mbstatus[1] = 1|2; break; - case WM_RBUTTONUP: if (!mouse_acquire) ext_mbstatus[1] &= ~2; break; -#ifndef NODRAW - case WM_ERASEBKGND: return(1); //flicker bug? - case WM_NCPAINT: if (fullscreen) return(0); break; //don't redraw window frame - flicker bug? -#endif - case WM_CLOSE: - if (catchwmclose) { if (!catchwmclose()) return(1); } - - //FYI: Application terminates in this order: - //if (keystatus[1]) Post(WM_CLOSE) //Located inside doframe - //WM_CLOSE: uninitdirect* //WARNING: must be before DestroyWindow! - // DestroyWindow! - // Post(WM_DESTROY) - //WM_DESTROY: Post(WM_QUIT) - //WM_QUIT: quitprogram = 1; - //if (quitprogram) exit(); -#ifndef NOINPUT - uninitmouse(); - uninitkeyboard(); - uninitdirectinput(); -#endif -#ifndef NOSOUND - uninitdirectsound(); -#endif -#ifndef NODRAW - uninitdirectdraw(); -#endif - uninitapp(); - break; - case WM_COMMAND: - { - // from a menu - if(HIWORD(wParam) == 0 && MenuFunc != NULL) - { - MenuFunc(LOWORD(wParam), (HANDLE)lParam); - } - break; - } - case WM_DESTROY: - //Does this remove taskbar icon? - UnregisterClass(wc.lpszClassName,ghinst); - PostQuitMessage(0); - return(0); - default: break; - } - return(DefWindowProc(hwnd,msg,wParam,lParam)); -} - -long keyread () -{ - long i; - - if (keybufr == keybufw) return(0); - i = keybuf[keybufr]; keybufr = ((keybufr+1)&(KEYBUFSIZ-1)); -#if 0 //defined(_DEBUG) && !defined(NODRAW) - if (((i>>8)&255) == 0x2e && (i&(3<<18))) { // && (i&(3<<20))) { - debugdirectdraw(); - if (ddrawdebugmode != -1) __asm { int 3 }; - } -#endif - return(i); -} - -void breath () -{ - MSG msg; - while (PeekMessage(&msg,0,0,0,PM_REMOVE)) //&msg,ghwnd, |PM_NOYIELD? - { - if (msg.message == WM_QUIT) { quitprogram = 1; quitparam = msg.wParam; return; } - TranslateMessage(&msg); - DispatchMessage(&msg); - } - keybufw = keybufw2; // to be safe with multithreads - -#ifndef NOSOUND -#if (USEKENSOUND == 1) - ENTERMUTX; - kensoundbreath(MINBREATHREND); - LEAVEMUTX; - umixerbreathe(); -#endif -#endif -} - - //10/20/2004: this code is useless now that quotes are automatically stripped off properly in WinMain() - //Call like this: arg2filename(argv[1],".ksm",curfilename); - //Make sure curfilename length is long enough! -void arg2filename (const char *oarg, const char *ext, char *narg) -{ - long i; - - //Chop off quotes at beginning and end of filename - for(i=strlen(oarg);i>0;i--) - if (oarg[i-1] == '\\') break; - if ((!i) && (oarg[0] == '\"')) i = 1; - strcpy(narg,&oarg[i]); - if (narg[0] == 0) return; - if (narg[strlen(narg)-1] == '\"') narg[strlen(narg)-1] = 0; - strlwr(narg); - if (!strstr(narg,ext)) strcat(narg,ext); -} - -#ifdef __WATCOMC__ - - //Precision: bits 8-9:, Rounding: bits 10-11: - //00 = 24-bit (0) 00 = nearest/even (0) - //01 = reserved (1) 01 = -inf (4) - //10 = 53-bit (2) 10 = inf (8) - //11 = 64-bit (3) 11 = 0 (c) -static long fpuasm[2]; -void fpuinit (long); -#pragma aux fpuinit =\ - "fninit"\ - "fstcw fpuasm"\ - "and byte ptr fpuasm[1], 0f0h"\ - "or byte ptr fpuasm[1], al"\ - "fldcw fpuasm"\ - parm [eax] - -#endif -#ifdef _MSC_VER - - //Precision: bits 8-9:, Rounding: bits 10-11: - //00 = 24-bit (0) 00 = nearest/even (0) - //01 = reserved (1) 01 = -inf (4) - //10 = 53-bit (2) 10 = inf (8) - //11 = 64-bit (3) 11 = 0 (c) -static long fpuasm[2]; -static _inline void fpuinit (long a) -{ - _asm - { - mov eax, a - fninit - fstcw fpuasm - and byte ptr fpuasm[1], 0f0h - or byte ptr fpuasm[1], al - fldcw fpuasm - } -} - -#endif - -#ifndef NO_CONSOLE - int main(int argc, char *argv[]) -#else - int WINAPI WinMain (HINSTANCE hinst, HINSTANCE hpinst, LPSTR cmdline, int ncmdshow) -#endif -{ - long i, j, k, inquote; - - Minidump::Activate(); - MemoryLeakFinder::Activate(); - -#ifndef NO_CONSOLE - HINSTANCE hinst = (HINSTANCE)GetModuleHandle(NULL); - HINSTANCE hpinst = 0; - LPSTR cmdline = ""; - int ncmdshow = SW_SHOW; -#endif - - ghinst = hinst; ghpinst = hpinst; gcmdline = cmdline; gncmdshow = ncmdshow; - - cputype = getcputype(); - if ((cputype&((1<<0)+(1<<4))) != ((1<<0)+(1<<4))) - { MessageBox(0,"Sorry, this program requires FPU&RDTSC support (>=Pentium)",prognam,MB_OK); return(-1); } - osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - GetVersionEx(&osvi); - - initklock(); -#ifndef NOINPUT - for(i=0;i<256;i++) keystatus[i] = 0; - for(i=0;i<256;i++) ext_keystatus[i] = 0; -#endif - -#ifdef NO_CONSOLE - //Convert Windows command line into ANSI 'C' command line... - int argc; - char *argv[MAX_PATH>>1]; - argv[0] = "exe"; argc = 1; j = inquote = 0; - for(i=0;cmdline[i];i++) - { - k = (((cmdline[i] != ' ') && (cmdline[i] != '\t')) || (inquote)); - if (cmdline[i] == '\"') inquote ^= 1; - if (j < k) { argv[argc++] = &cmdline[i+inquote]; j = inquote+1; continue; } - if ((j) && (!k)) - { - if ((j == 2) && (cmdline[i-1] == '\"')) cmdline[i-1] = 0; - cmdline[i] = 0; j = 0; - } - } - if ((j == 2) && (cmdline[i-1] == '\"')) cmdline[i-1] = 0; - argv[argc] = 0; -#endif - if (initapp(argc,argv) < 0) return(-1); - - wc.style = CS_HREDRAW | CS_VREDRAW; - wc.lpfnWndProc = WindowProc; - wc.cbClsExtra = wc.cbWndExtra = 0; - wc.hInstance = ghinst; - wc.hIcon = LoadIcon(ghinst,IDI_APPLICATION); - wc.hCursor = LoadCursor(0,IDC_ARROW); -#ifndef NODRAW - wc.hbrBackground = 0; -#else -#ifdef _MSC_VER - //wc.hbrBackground = (HBRUSH__ *)GetStockObject(BLACK_BRUSH); - wc.hbrBackground = (struct HBRUSH__ *)GetStockObject(BLACK_BRUSH); -#endif -#ifdef __WATCOMC__ - wc.hbrBackground = GetStockObject(BLACK_BRUSH); -#endif -#endif - wc.lpszMenuName = 0; - wc.lpszClassName = prognam; - RegisterClass(&wc); - - progwndflags = WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX; - progwndadd[1] = GetSystemMetrics(SM_CYCAPTION); - if (progresiz) { - progwndflags |= WS_MAXIMIZEBOX|WS_THICKFRAME; - progwndadd[0] = GetSystemMetrics(SM_CXSIZEFRAME)*2; - progwndadd[1] += GetSystemMetrics(SM_CYSIZEFRAME)*2; - } else { - progwndadd[0] = GetSystemMetrics(SM_CXFIXEDFRAME)*2; - progwndadd[1] += GetSystemMetrics(SM_CYFIXEDFRAME)*2; - } - -#ifndef NODRAW - if (fullscreen) - { - if ((ghwnd = CreateWindowEx(WS_EX_TOPMOST,prognam,prognam,WS_POPUP,0,0,GetSystemMetrics(SM_CXSCREEN), - GetSystemMetrics(SM_CYSCREEN),0,0,ghinst,0)) == 0) return(0); - } - else - { -#endif - if (progwndx == 0x80000000) - { - RECT rw; - SystemParametersInfo(SPI_GETWORKAREA,0,&rw,0); - progwndx = ((rw.right -rw.left-(xres+progwndadd[0]))>>1) + rw.left; - progwndy = ((rw.bottom-rw.top -(yres+progwndadd[1]))>>1) + rw.top; - } - if ((ghwnd = CreateWindowEx(0,prognam,prognam,progwndflags, - progwndx,progwndy,xres+progwndadd[0],yres+progwndadd[1],0,0,ghinst,0)) == 0) return(0); -#ifndef NODRAW - } -#endif - - ShowWindow(ghwnd,gncmdshow); -#ifndef NODRAW - if ((!fullscreen) && (gncmdshow == SW_MAXIMIZE)) - { - RECT rw; - SystemParametersInfo(SPI_GETWORKAREA,0,&rw,0); - xres = rw.right -rw.left; - yres = rw.bottom-rw.top; - } -#endif - - //Enable this for smooth start-up, but beware: it halts disk caches! - //HANDLE hProc = GetCurrentProcess(); - //SetPriorityClass(hProc,REALTIME_PRIORITY_CLASS); - -#ifndef NODRAW - if (!initdirectdraw(xres,yres,colbits)) { DestroyWindow(ghwnd); return(0); } -#endif -#if 0 //defined(_DEBUG) && !defined(NODRAW) - debugdirectdraw(); // enable debug mode by default -#endif - -#ifndef NOSOUND -#ifdef DSOUNDINITCOM - coinit = CoInitialize(NULL); -#endif - initdirectsound(); -#endif - - UpdateWindow(ghwnd); - -#ifndef NOINPUT - if (!initdirectinput(ghwnd)) - { - DestroyWindow(ghwnd); -#ifndef NOSOUND - uninitdirectsound(); -#endif -#ifndef NODRAW - uninitdirectdraw(); -#endif - return(0); - } - if (!initkeyboard(ghwnd)) - { - uninitdirectinput(); DestroyWindow(ghwnd); -#ifndef NOSOUND - uninitdirectsound(); -#endif -#ifndef NODRAW - uninitdirectdraw(); -#endif - return(0); - } - if (!initmouse(ghwnd)) - { - uninitkeyboard(); uninitdirectinput(); DestroyWindow(ghwnd); -#ifndef NOSOUND - uninitdirectsound(); -#endif -#ifndef NODRAW - uninitdirectdraw(); -#endif - return(0); - } -#endif - -#if ((USEKENSOUND == 1) && (USETHREADS != 0)) - if (dsound) - { - hmutx = CreateMutex(0,0,0); - _beginthread(kensoundthread,0,0); - } -#endif - - initapp2(); - - breath(); - while (!quitprogram) - { - if (alwaysactive || ActiveApp) { fpuinit(0x2); doframe(); } - else WaitMessage(); - breath(); - } -#if ((USEKENSOUND == 1) && (USETHREADS != 0)) - if (dsound) - { - while (quitprogram != 2) Sleep(USETHREADS); - ENTERMUTX; - CloseHandle(hmutx); - } -#endif -#ifndef NOSOUND -#ifdef DSOUNDINITCOM - if (coinit == S_OK) CoUninitialize(); -#endif -#endif - - MemoryLeakFinder::DumpStatistics(); - - return(quitparam); -} diff --git a/bin/win64/shader.png b/bin/win64/shader.png deleted file mode 100644 index 4815bca..0000000 Binary files a/bin/win64/shader.png and /dev/null differ diff --git a/build/Asura.Editor/Asura.Editor.vcxproj b/build/Asura.Editor/Asura.Editor.vcxproj index 72dc736..b2168db 100644 --- a/build/Asura.Editor/Asura.Editor.vcxproj +++ b/build/Asura.Editor/Asura.Editor.vcxproj @@ -117,47 +117,51 @@ - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + - - - - - + + + + + + + diff --git a/build/Asura.Editor/Asura.Editor.vcxproj.filters b/build/Asura.Editor/Asura.Editor.vcxproj.filters index 0e979a4..a535cb8 100644 --- a/build/Asura.Editor/Asura.Editor.vcxproj.filters +++ b/build/Asura.Editor/Asura.Editor.vcxproj.filters @@ -1,134 +1,149 @@ 锘 - - {7654ef3d-54c4-490f-bb24-e6a67bd63e1e} + + {a4345092-d09c-424c-8d7c-c076914fb6a2} - + {f67906bd-4f7c-4ac6-bca1-019617435a8b} - - {48600309-cddd-49cd-b939-7a19a2b1eaa3} - - + {4be8ce5c-0921-4341-a976-92d31aa84c8c} - + {b4c26f9c-9f4e-4332-a6e2-33456b4abecb} - - {a236e36b-9b74-48a2-a4c9-f70dbb321f14} + + {7654ef3d-54c4-490f-bb24-e6a67bd63e1e} + + + {48600309-cddd-49cd-b939-7a19a2b1eaa3} + + + {1e378398-d7f0-4616-a986-b6a86faeaa8c} - - layout + + Controls + + + Controls - - layout + + Controls - - - - system + + Controls - - graphics + + Controls - - graphics + + Graphics - - graphics + + Graphics - - graphics + + Graphics - - system + + Graphics - - graphics + + Graphics - - controls + + Layout - - controls + + Layout - - controls + + System - - controls + + + + Controls - - controls + + System - - controls + + System + + + Controls - - layout + + Graphics\shaders - - layout + + Graphics\shaders - - - system + + Controls - - - - graphics + + Controls - - graphics\shaders + + Controls - - graphics + + Controls - - graphics + + Controls - - graphics + + Core - - graphics + + Graphics - - graphics\shaders + + Graphics + + + Graphics + + + Graphics - - system + + Graphics - - core + + Graphics - - graphics + + Layout - - controls + + Layout - - controls + + System - - controls + + + + + Controls - - controls + + System - - controls + + System - - controls + + Controls \ No newline at end of file diff --git a/build/Asura.Runner/Asura.Runner.vcxproj b/build/Asura.Runner/Asura.Runner.vcxproj index ecf025b..0c18dc5 100644 --- a/build/Asura.Runner/Asura.Runner.vcxproj +++ b/build/Asura.Runner/Asura.Runner.vcxproj @@ -18,13 +18,6 @@ x64 - - - - - - - 15.0 {E21A839A-C7C6-4B83-89FB-C921AEBEA9CD} @@ -83,7 +76,6 @@ Disabled true true - $(SolutionDir)..\source\external;$(SolutionDir)..\source\modules;%(AdditionalIncludeDirectories) @@ -116,13 +108,14 @@ true true true - $(SolutionDir)..\source\external;$(SolutionDir)..\source\modules;%(AdditionalIncludeDirectories) true true + + diff --git a/build/Asura.Runner/Asura.Runner.vcxproj.filters b/build/Asura.Runner/Asura.Runner.vcxproj.filters index 1819f86..3c6f4fd 100644 --- a/build/Asura.Runner/Asura.Runner.vcxproj.filters +++ b/build/Asura.Runner/Asura.Runner.vcxproj.filters @@ -1,10 +1,17 @@ 锘 - - - - - + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;ipp;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + \ No newline at end of file diff --git a/build/external/Luax/Luax.vcxproj b/build/external/Luax/Luax.vcxproj index b9b130d..4ea48a3 100644 --- a/build/external/Luax/Luax.vcxproj +++ b/build/external/Luax/Luax.vcxproj @@ -154,8 +154,8 @@ - - + + diff --git a/build/external/Luax/Luax.vcxproj.filters b/build/external/Luax/Luax.vcxproj.filters index afb32e8..9029fa7 100644 --- a/build/external/Luax/Luax.vcxproj.filters +++ b/build/external/Luax/Luax.vcxproj.filters @@ -28,7 +28,7 @@ - - + + \ No newline at end of file diff --git a/build/modules/asura-base/asura-base.vcxproj b/build/modules/asura-base/asura-base.vcxproj index 970e6b1..f49fccb 100644 --- a/build/modules/asura-base/asura-base.vcxproj +++ b/build/modules/asura-base/asura-base.vcxproj @@ -18,6 +18,9 @@ x64 + + + 15.0 {E10B78AA-B90E-4BB7-BAAD-0E2E4C4B9BD1} @@ -119,9 +122,6 @@ true - - - diff --git a/build/modules/asura-base/asura-base.vcxproj.filters b/build/modules/asura-base/asura-base.vcxproj.filters index bd24c8d..cae08e9 100644 --- a/build/modules/asura-base/asura-base.vcxproj.filters +++ b/build/modules/asura-base/asura-base.vcxproj.filters @@ -1,6 +1,6 @@ 锘 - + \ No newline at end of file diff --git a/build/modules/asura-box2d/asura-box2d.vcxproj b/build/modules/asura-box2d/asura-box2d.vcxproj index 485460a..b41df12 100644 --- a/build/modules/asura-box2d/asura-box2d.vcxproj +++ b/build/modules/asura-box2d/asura-box2d.vcxproj @@ -117,32 +117,32 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - + diff --git a/build/modules/asura-box2d/asura-box2d.vcxproj.filters b/build/modules/asura-box2d/asura-box2d.vcxproj.filters index a7a33eb..5415a04 100644 --- a/build/modules/asura-box2d/asura-box2d.vcxproj.filters +++ b/build/modules/asura-box2d/asura-box2d.vcxproj.filters @@ -1,89 +1,89 @@ 锘 - - - physics + + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - - physics + + Physics - + {c01b5c57-f3a7-445f-aed3-e0a27dbe74c2} - + {3fb6587c-0c9d-4f6e-9e72-653032d9b238} - - physics\binding + Physics\binding - physics\binding + Physics\binding + \ No newline at end of file diff --git a/build/modules/asura-core/asura-core.vcxproj b/build/modules/asura-core/asura-core.vcxproj index fcb37c4..a14c816 100644 --- a/build/modules/asura-core/asura-core.vcxproj +++ b/build/modules/asura-core/asura-core.vcxproj @@ -122,11 +122,11 @@ - - - - - + + + + + @@ -139,104 +139,102 @@ - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -252,6 +250,10 @@ {7d41093f-e356-4c5b-a25f-41779bf86e54} + + + + diff --git a/build/modules/asura-core/asura-core.vcxproj.filters b/build/modules/asura-core/asura-core.vcxproj.filters index c7b664b..6c45670 100644 --- a/build/modules/asura-core/asura-core.vcxproj.filters +++ b/build/modules/asura-core/asura-core.vcxproj.filters @@ -1,371 +1,377 @@ 锘 - + {a338aae6-b932-4a59-9a2e-f07283aaea64} - - {18c6a104-a8f9-4794-80a0-2fe9afdfca3e} - - - {1a6ed8b6-908c-458d-a036-1ff57db1248a} + + {4f6b2c19-1a06-48c9-b89d-52fa27bec5c1} - + {3a06866e-ed35-485f-94a5-548b522fd1f4} - - {81dedac2-8d27-4c19-bf40-1503f0dbad1b} + + {5061f7d5-03a9-480a-83eb-35d9806abde3} - - {4f6b2c19-1a06-48c9-b89d-52fa27bec5c1} + + {43e14e72-d4cb-47b8-b55c-7327a6fc0508} - - {05477a0e-f70b-4606-ae96-82ef7a7b8a1d} + + {18c6a104-a8f9-4794-80a0-2fe9afdfca3e} - + {66e43743-1be3-414a-9f3c-473d40613892} - - {5061f7d5-03a9-480a-83eb-35d9806abde3} - - + {0a758ae6-91a0-462a-968f-aa3412a714ae} - + + {1a6ed8b6-908c-458d-a036-1ff57db1248a} + + + {81dedac2-8d27-4c19-bf40-1503f0dbad1b} + + {7a73607c-8da6-4865-a992-5c7c8764bd5a} - + {139aa01b-d038-4361-9edd-f81d8ba37730} - - {43e14e72-d4cb-47b8-b55c-7327a6fc0508} + + {05477a0e-f70b-4606-ae96-82ef7a7b8a1d} - - - graphics + + Graphics\Binding - - graphics + + Graphics\Binding - - graphics + + Graphics\Binding + + + Graphics\Binding - - graphics + + Graphics\Binding - - graphics + + Graphics\Binding - - graphics + + Graphics\Binding - - graphics + + Graphics\Binding - - graphics + + Window\binding - - graphics + + Image\binding - - font + + Image\binding - - font + + Graphics\Binding - - font + + Graphics\Binding - - time + + Graphics\Binding - - profiler + + Graphics\Binding - - - graphics + + Font - - graphics\binding + + Font - - graphics\binding + + Font - - graphics\binding + + Graphics - - graphics\binding + + Graphics - - graphics\binding + + Graphics - - graphics\binding + + Graphics - - graphics\binding + + Graphics - - threading + + Graphics - - threading + + Graphics - - graphics + + Graphics - - graphics\binding + + Graphics - - input + + Graphics - - image + + Graphics - - image + + Graphics - - image + + Graphics - - image + + Graphics - - mesh + + Graphics - - window + + Graphics - - window + + Image - - window + + Image - - window + + Image - - window\binding + + Image - - image\binding + + Input - - image\binding + + Input - - graphics + + Input - - graphics + + Mesh - - mesh + + Mesh - - mesh + + Mesh - - mesh + + Mesh - - graphics\binding + + Profiler - - graphics + + Profiler - - graphics + + Time - - graphics\binding + + Window - - graphics\binding + + Window - - graphics + + Window - - graphics\binding + + Window - - profiler + + + + Threads - - input + + Threads - - input + + Graphics - - - graphics + + Font - - graphics + + Font - - graphics + + Font - - graphics + + Graphics - - graphics + + Graphics - - graphics + + Graphics - - graphics + + Graphics - - graphics + + Graphics - - graphics + + Graphics - - graphics + + Graphics - - graphics + + Graphics - - graphics + + Graphics - - font + + Graphics - - font + + Graphics - - font + + Graphics - - font + + Graphics - - time + + Graphics - - profiler + + Graphics - - - - - graphics + + Graphics - - threading + + Graphics - - threading + + Graphics - - graphics + + Graphics - - input + + Image - - image + + Image - - image + + Image - - image + + Image - - image + + Image - - image + + Input - - mesh + + Input - - window + + Input - - window + + Input - - window + + Input - - window + + Input - - graphics + + Input - - graphics + + Input - - mesh + + Mesh - - mesh + + Mesh - - mesh + + Mesh - - graphics + + Mesh - - graphics + + Profiler - - graphics + + Profiler - - profiler + + Time - - input + + Window - - input + + Window - - input + + Window - - input + + Window - - input + + + + + + Threads - - input + + Threads + + + Font + + + Graphics - - font - - - font + + Font - - input + + Font \ No newline at end of file diff --git a/build/modules/asura-fmod/asura-fmod.vcxproj b/build/modules/asura-fmod/asura-fmod.vcxproj index a12412a..3852905 100644 --- a/build/modules/asura-fmod/asura-fmod.vcxproj +++ b/build/modules/asura-fmod/asura-fmod.vcxproj @@ -18,6 +18,10 @@ x64 + + + + 15.0 {CC451230-39E1-403A-8E1F-C3E7982049E5} @@ -114,10 +118,6 @@ true - - - - diff --git a/build/modules/asura-fmod/asura-fmod.vcxproj.filters b/build/modules/asura-fmod/asura-fmod.vcxproj.filters index fbde100..66b3669 100644 --- a/build/modules/asura-fmod/asura-fmod.vcxproj.filters +++ b/build/modules/asura-fmod/asura-fmod.vcxproj.filters @@ -1,14 +1,14 @@ 锘 - + {f6eae779-a9f2-4f5f-a62b-5d0fbf4cdc1b} - - audio + + Audio - + \ No newline at end of file diff --git a/build/modules/asura-json/asura-json.vcxproj b/build/modules/asura-json/asura-json.vcxproj index 56a807b..64af220 100644 --- a/build/modules/asura-json/asura-json.vcxproj +++ b/build/modules/asura-json/asura-json.vcxproj @@ -18,6 +18,14 @@ x64 + + + + + + + + 15.0 {1B83A353-9694-42E0-997E-79E150E1C2E5} @@ -116,14 +124,6 @@ true - - - - - - - - diff --git a/build/modules/asura-json/asura-json.vcxproj.filters b/build/modules/asura-json/asura-json.vcxproj.filters index 97944e6..7f255cb 100644 --- a/build/modules/asura-json/asura-json.vcxproj.filters +++ b/build/modules/asura-json/asura-json.vcxproj.filters @@ -1,20 +1,20 @@ 锘 - - - json - + + {2884af6d-6bc5-4714-8b32-32edd8099000} + - - - json - + + Json + + - - {2884af6d-6bc5-4714-8b32-32edd8099000} - + + Json + + \ No newline at end of file diff --git a/build/modules/asura-log/asura-log.vcxproj.filters b/build/modules/asura-log/asura-log.vcxproj.filters index 3c6f4fd..9cd8510 100644 --- a/build/modules/asura-log/asura-log.vcxproj.filters +++ b/build/modules/asura-log/asura-log.vcxproj.filters @@ -1,17 +1,2 @@ 锘 - - - - {4FC737F1-C7A5-4376-A066-2A32D752A2FF} - cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx - - - {93995380-89BD-4b04-88EB-625FBE52EBFB} - h;hh;hpp;hxx;hm;inl;inc;ipp;xsd - - - {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} - rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms - - - \ No newline at end of file + \ No newline at end of file diff --git a/build/modules/asura-network/asura-network.vcxproj b/build/modules/asura-network/asura-network.vcxproj index 198777e..f18b768 100644 --- a/build/modules/asura-network/asura-network.vcxproj +++ b/build/modules/asura-network/asura-network.vcxproj @@ -19,7 +19,7 @@ - + 15.0 diff --git a/build/modules/asura-network/asura-network.vcxproj.filters b/build/modules/asura-network/asura-network.vcxproj.filters index a475832..67825d4 100644 --- a/build/modules/asura-network/asura-network.vcxproj.filters +++ b/build/modules/asura-network/asura-network.vcxproj.filters @@ -1,11 +1,11 @@ 锘 - + {c48e682b-c747-4a26-aabc-98e5d05c179c} - + \ No newline at end of file diff --git a/build/modules/asura-openal/asura-openal.vcxproj b/build/modules/asura-openal/asura-openal.vcxproj index b96d3c4..5a9ae35 100644 --- a/build/modules/asura-openal/asura-openal.vcxproj +++ b/build/modules/asura-openal/asura-openal.vcxproj @@ -18,6 +18,26 @@ x64 + + + + + + + + + + + + + + + + + + + + 15.0 {088C6ABA-26A6-43D1-8492-096EDB65597C} @@ -116,26 +136,6 @@ true - - - - - - - - - - - - - - - - - - - - diff --git a/build/modules/asura-openal/asura-openal.vcxproj.filters b/build/modules/asura-openal/asura-openal.vcxproj.filters index 4a7af79..23e13cd 100644 --- a/build/modules/asura-openal/asura-openal.vcxproj.filters +++ b/build/modules/asura-openal/asura-openal.vcxproj.filters @@ -1,63 +1,63 @@ 锘 - - audio + + {35f52c38-26da-43eb-9ca2-8c5d32f38b37} + + + {dbd7324a-d1b4-4370-ba8d-df87b31d984c} + + + + + Audio - - audio + + Audio - - audio + + Audio - - audio + + Audio - - audio + + Audio - - audio + + Audio - - audio + + Audio - - audio + + Audio - - audio + + Audio - - audio + + Audio - - audio + + Audio - - audio + + Audio - - audio + + Audio - - audio + + Audio - - audio + + Audio - - audio + + Audio - - - {35f52c38-26da-43eb-9ca2-8c5d32f38b37} - - - {dbd7324a-d1b4-4370-ba8d-df87b31d984c} - - \ No newline at end of file diff --git a/build/modules/asura-plot/asura-plot.vcxproj.filters b/build/modules/asura-plot/asura-plot.vcxproj.filters index 13e717f..b4068b5 100644 --- a/build/modules/asura-plot/asura-plot.vcxproj.filters +++ b/build/modules/asura-plot/asura-plot.vcxproj.filters @@ -1,7 +1,7 @@ 锘 - + {0f829a34-bb64-4d78-b97a-32c6679fc43b} diff --git a/build/modules/asura-steam/asura-steam.vcxproj.filters b/build/modules/asura-steam/asura-steam.vcxproj.filters index d48ea8c..aa62925 100644 --- a/build/modules/asura-steam/asura-steam.vcxproj.filters +++ b/build/modules/asura-steam/asura-steam.vcxproj.filters @@ -1,7 +1,7 @@ 锘 - + {73580bc7-0dec-4284-a31a-9a84f284326a} diff --git a/build/modules/asura-utils/asura-utils.vcxproj b/build/modules/asura-utils/asura-utils.vcxproj index c84c5a5..f314953 100644 --- a/build/modules/asura-utils/asura-utils.vcxproj +++ b/build/modules/asura-utils/asura-utils.vcxproj @@ -122,89 +122,84 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -217,6 +212,12 @@ {aee37589-de0d-4139-8bdb-8179fdefb835} + + + + + + diff --git a/build/modules/asura-utils/asura-utils.vcxproj.filters b/build/modules/asura-utils/asura-utils.vcxproj.filters index 027855d..1305948 100644 --- a/build/modules/asura-utils/asura-utils.vcxproj.filters +++ b/build/modules/asura-utils/asura-utils.vcxproj.filters @@ -1,245 +1,253 @@ 锘 - + {30702383-d458-4486-8d86-bd98db74d3c8} - - {d46782e8-fa86-46be-8e3e-728d313acfed} - - - {3a94ee03-c8db-4d2e-b0b6-5f6ba157580d} - - + {6eb6ffb5-ecd9-408b-a2f4-c14837822850} - + {b4b078e1-bb8d-4cb3-84b9-963e851be123} - + + {d46782e8-fa86-46be-8e3e-728d313acfed} + + + {3a94ee03-c8db-4d2e-b0b6-5f6ba157580d} + + {d617f453-4cd1-451b-801d-2f88d0072303} - + {e63982e2-a2ca-4aa2-be11-f98659586c1f} + + {6f471cc5-a89f-4be8-ba69-f04a5dd187f0} + - - exceptions + + IO\binding - - math + + IO\binding - - math + + IO\binding - - math + + IO\binding - - math + + IO\binding - - math + + IO\binding - - - - io\binding + + Exceptions - - io\binding + + IO - - io + + IO - - io + + IO - - io + + IO - - io + + IO - - io\binding + + IO - - io\binding + + IO - - io + + Math - - io\binding + + Math - - threading + + Math - - threading + + Math - - threading + + Math - - threading + + Math - - threading + + + + Threads\binding - - threading + + Threads\binding - - io + + Threads - - threading + + Threads - - threading\binding + + Threads - - threading\binding + + Threads - - io\binding + + Threads - - math + + Threads - - threading + + Threads - - threading + + Threads - - io + + Threads - - threading + + Threads - - exceptions + + Exceptions + + + IO + + + IO - - math + + IO - - math + + IO - - math + + IO - - math + + IO - - math + + IO - - math + + IO - - math + + Math - - math + + Math - - math + + Math - - scripting + + Math - - - - - - - - - - io + + Math - - io + + Math - - io + + Math - - io + + Math - - io + + Math - - io + + Math - - threading + + Scripting - - threading + + + + + + + + + + Threads - - threading + + Threads - - threading + + Threads - - threading + + Threads - - threading + + Threads - - io + + Threads - - threading + + Threads - - math + + Threads - - threading + + Threads - - threading + + Threads - - io + + Threads - - threading + + Math\Rand - - threading + + + Math\Rand - - - - math + + Math - - math + + Math - - math + + Math - - math + + Math \ No newline at end of file diff --git a/build/modules/asura-xml/asura-xml.vcxproj.filters b/build/modules/asura-xml/asura-xml.vcxproj.filters index d4c889c..d8f61eb 100644 --- a/build/modules/asura-xml/asura-xml.vcxproj.filters +++ b/build/modules/asura-xml/asura-xml.vcxproj.filters @@ -1,7 +1,7 @@ 锘 - + {d8671556-9eb0-4627-a264-e7b667109bc4} diff --git a/build/tools/bindingGen/obj/Debug/bindingGen.exe b/build/tools/bindingGen/obj/Debug/bindingGen.exe index db18b14..5053131 100644 Binary files a/build/tools/bindingGen/obj/Debug/bindingGen.exe and b/build/tools/bindingGen/obj/Debug/bindingGen.exe differ diff --git a/source/Asura.Editor/Config.h b/source/Asura.Editor/Config.h new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Controls/GUIButton.cpp b/source/Asura.Editor/Controls/GUIButton.cpp new file mode 100644 index 0000000..f168982 --- /dev/null +++ b/source/Asura.Editor/Controls/GUIButton.cpp @@ -0,0 +1,11 @@ +#include "GUIButton.h" + +namespace_begin(AsuraEditor) + +bool GUIButton() +{ + return false; +} + + +namespace_end diff --git a/source/Asura.Editor/Controls/GUIButton.h b/source/Asura.Editor/Controls/GUIButton.h new file mode 100644 index 0000000..ece60ca --- /dev/null +++ b/source/Asura.Editor/Controls/GUIButton.h @@ -0,0 +1,14 @@ +#ifndef _ASURA_EDITOR_GUI_BUTTON_H_ +#define _ASURA_EDITOR_GUI_BUTTON_H_ + +#include + +namespace_begin(AsuraEditor) + +bool GUIButton(); + + + +namespace_end + +#endif diff --git a/source/Asura.Editor/Controls/GUIContent.cpp b/source/Asura.Editor/Controls/GUIContent.cpp new file mode 100644 index 0000000..c5741c1 --- /dev/null +++ b/source/Asura.Editor/Controls/GUIContent.cpp @@ -0,0 +1,8 @@ +#include "gui_button.h" + +namespace_begin(AsuraEditor) + + + + +namespace_end diff --git a/source/Asura.Editor/Controls/GUIContent.h b/source/Asura.Editor/Controls/GUIContent.h new file mode 100644 index 0000000..c70a03c --- /dev/null +++ b/source/Asura.Editor/Controls/GUIContent.h @@ -0,0 +1,17 @@ +#ifndef _ASURA_EDITOR_GUI_CONTENT_H_ +#define _ASURA_EDITOR_GUI_CONTENT_H_ + +#include + +namespace_begin(AsuraEditor) + +/// IMGUI content +class GUIContent +{ + +}; + + +namespace_end + +#endif diff --git a/source/Asura.Editor/Controls/GUILabel.cpp b/source/Asura.Editor/Controls/GUILabel.cpp new file mode 100644 index 0000000..c5741c1 --- /dev/null +++ b/source/Asura.Editor/Controls/GUILabel.cpp @@ -0,0 +1,8 @@ +#include "gui_button.h" + +namespace_begin(AsuraEditor) + + + + +namespace_end diff --git a/source/Asura.Editor/Controls/GUILabel.h b/source/Asura.Editor/Controls/GUILabel.h new file mode 100644 index 0000000..172a329 --- /dev/null +++ b/source/Asura.Editor/Controls/GUILabel.h @@ -0,0 +1,14 @@ +#ifndef _ASURA_EDITOR_GUI_LABEL_H_ +#define _ASURA_EDITOR_GUI_LABEL_H_ + +#include + +namespace_begin(AsuraEditor) + +bool GUILabel(); + + + +namespace_end + +#endif diff --git a/source/Asura.Editor/Controls/GUIPanel.cpp b/source/Asura.Editor/Controls/GUIPanel.cpp new file mode 100644 index 0000000..3a78af7 --- /dev/null +++ b/source/Asura.Editor/Controls/GUIPanel.cpp @@ -0,0 +1,6 @@ +#include "GUIPanel.h" + +namespace_begin(AsuraEditor) + + +namespace_end diff --git a/source/Asura.Editor/Controls/GUIPanel.h b/source/Asura.Editor/Controls/GUIPanel.h new file mode 100644 index 0000000..6bcd00d --- /dev/null +++ b/source/Asura.Editor/Controls/GUIPanel.h @@ -0,0 +1,16 @@ +#ifndef _ASURA_EDITOR_GUI_PANEL_H_ +#define _ASURA_EDITOR_GUI_PANEL_H_ + +#include + +namespace_begin(AsuraEditor) + +/// IMGUI panel +class GUIPanel +{ + +}; + +namespace_end + +#endif diff --git a/source/Asura.Editor/Controls/GUISlider.cpp b/source/Asura.Editor/Controls/GUISlider.cpp new file mode 100644 index 0000000..9c20d5f --- /dev/null +++ b/source/Asura.Editor/Controls/GUISlider.cpp @@ -0,0 +1,8 @@ +#include "GUISlider.h" + +namespace_begin(AsuraEditor) + + + + +namespace_end diff --git a/source/Asura.Editor/Controls/GUISlider.h b/source/Asura.Editor/Controls/GUISlider.h new file mode 100644 index 0000000..8d91e85 --- /dev/null +++ b/source/Asura.Editor/Controls/GUISlider.h @@ -0,0 +1,14 @@ +#ifndef _ASURA_EDITOR_GUI_SLIDER_H_ +#define _ASURA_EDITOR_GUI_SLIDER_H_ + +#include + +namespace_begin(AsuraEditor) + +void GUISlider(); + + +namespace_end + + +#endif diff --git a/source/Asura.Editor/Controls/GUIToggle.cpp b/source/Asura.Editor/Controls/GUIToggle.cpp new file mode 100644 index 0000000..7871098 --- /dev/null +++ b/source/Asura.Editor/Controls/GUIToggle.cpp @@ -0,0 +1 @@ +#include "GUIToggle.h" diff --git a/source/Asura.Editor/Controls/GUIToggle.h b/source/Asura.Editor/Controls/GUIToggle.h new file mode 100644 index 0000000..b26e919 --- /dev/null +++ b/source/Asura.Editor/Controls/GUIToggle.h @@ -0,0 +1,16 @@ +#ifndef _ASURA_EDITOR_GUI_TOGGLE_H_ +#define _ASURA_EDITOR_GUI_TOGGLE_H_ + +#include + +namespace_begin(AsuraEditor) + +/// Radio button \ toggle button + +bool GUIToggle(); + + + +namespace_end + +#endif diff --git a/source/Asura.Editor/Controls/TextUtil.cpp b/source/Asura.Editor/Controls/TextUtil.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Controls/TextUtil.h b/source/Asura.Editor/Controls/TextUtil.h new file mode 100644 index 0000000..24fb1e1 --- /dev/null +++ b/source/Asura.Editor/Controls/TextUtil.h @@ -0,0 +1,37 @@ +#ifndef _ASURA_EDITOR_TEXTUTIL_H_ +#define _ASURA_EDITOR_TEXTUTIL_H_ + +#include + +namespace_begin(AsuraEditor) + +enum TextAlignment { + kLeft, + kCenter, + kRight, + kAuto, +}; + +enum TextAnchor { + kUpperLeft, + kUpperCenter, + kUpperRight, + kMiddleLeft, + kMiddleCenter, + kMiddleRight, + kLowerLeft, + kLowerCenter, + kLowerRight, + kDontCare ///< Special case for getting text mesh generators: The anchoring used for the text doesn't modify the size of the generated text, so if you just want to query for it you don't care about anchoring +}; + +enum TextClipping { + /// Text flows freely outside the element. + kOverflow = 0, + /// Text gets clipped to be inside the element. + kClip = 1, +}; + +namespace_end + +#endif \ No newline at end of file diff --git a/source/Asura.Editor/Core/GUIState.h b/source/Asura.Editor/Core/GUIState.h new file mode 100644 index 0000000..88c9891 --- /dev/null +++ b/source/Asura.Editor/Core/GUIState.h @@ -0,0 +1,27 @@ +#ifndef _ASURA_EDITOR_GUI_STATE_H_ +#define _ASURA_EDITOR_GUI_STATE_H_ + +#include + +namespace_begin(AsuraEditor) + +/// GUI widgets uniqueID +class GUIState +{ +public: + + inline int GetDepth() { return m_Depth; }; + +private: + + int m_Depth; + bool m_Changed; + +}; + + +namespace_end + + +#endif + diff --git a/source/Asura.Editor/Editor.cpp b/source/Asura.Editor/Editor.cpp new file mode 100644 index 0000000..38e7c26 --- /dev/null +++ b/source/Asura.Editor/Editor.cpp @@ -0,0 +1,5 @@ + +int main(int argc, char *argv[]) +{ + +} \ No newline at end of file diff --git a/source/Asura.Editor/Editor.h b/source/Asura.Editor/Editor.h new file mode 100644 index 0000000..2f5f8ca --- /dev/null +++ b/source/Asura.Editor/Editor.h @@ -0,0 +1,37 @@ +#ifndef _ASURA_EDITOR_H_ +#define _ASURA_EDITOR_H_ + +#include + +namespace AsuraEditor +{ + + /// + /// 编辑器实例。 + /// + class Editor + { + public: + + /// + /// 获得界面的lua State + /// + Luax::LuaxState& GetLuaxState(); + + private: + + /// + /// 界面和逻辑运行的虚拟机。 + /// + Luax::LuaxVM* mEditorVM; + + /// + /// 游戏运行时的虚拟机。 + /// + Luax::LuaxVM* mRunnerVM; + + }; + +} + +#endif \ No newline at end of file diff --git a/source/Asura.Editor/Editor/asset_view.lua b/source/Asura.Editor/Editor/asset_view.lua new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Editor/compile.bat b/source/Asura.Editor/Editor/compile.bat new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Editor/compile.sh b/source/Asura.Editor/Editor/compile.sh new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Editor/idea.txt b/source/Asura.Editor/Editor/idea.txt new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Editor/main.lua b/source/Asura.Editor/Editor/main.lua new file mode 100644 index 0000000..76fab7a --- /dev/null +++ b/source/Asura.Editor/Editor/main.lua @@ -0,0 +1,4 @@ + +--编辑器入口 +--编辑器真正的内容在Asura.Editor/scripts下面实现 + diff --git a/source/Asura.Editor/Editor/scene_view.lua b/source/Asura.Editor/Editor/scene_view.lua new file mode 100644 index 0000000..b6097f3 --- /dev/null +++ b/source/Asura.Editor/Editor/scene_view.lua @@ -0,0 +1,4 @@ +-- 鍦烘櫙绐楀彛 +local scene = AsuraEditor.Window.New("Window/Scene View") + + diff --git a/source/Asura.Editor/Graphics/Brush.cpp b/source/Asura.Editor/Graphics/Brush.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Graphics/Brush.h b/source/Asura.Editor/Graphics/Brush.h new file mode 100644 index 0000000..4290926 --- /dev/null +++ b/source/Asura.Editor/Graphics/Brush.h @@ -0,0 +1,20 @@ +#ifndef _ASURA_EDITOR_BRUSH_H_ +#define _ASURA_EDITOR_BRUSH_H_ + +namespace AsuraEditor +{ + namespace Graphics + { + + /// + /// 画刷,指定填充模式 + /// + class Brush + { + + }; + + } +} + +#endif \ No newline at end of file diff --git a/source/Asura.Editor/Graphics/DrawInfo.cpp b/source/Asura.Editor/Graphics/DrawInfo.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Graphics/DrawInfo.h b/source/Asura.Editor/Graphics/DrawInfo.h new file mode 100644 index 0000000..ee38319 --- /dev/null +++ b/source/Asura.Editor/Graphics/DrawInfo.h @@ -0,0 +1,16 @@ +#ifndef _ASURA_EDITOR_DRAW_INFO_H_ +#define _ASURA_EDITOR_DRAW_INFO_H_ + +#include + +namespace_begin(AsuraEditor) + +class DrawInfo +{ + +}; + + +namespace_end + +#endif \ No newline at end of file diff --git a/source/Asura.Editor/Graphics/Drawer.cpp b/source/Asura.Editor/Graphics/Drawer.cpp new file mode 100644 index 0000000..6482aeb --- /dev/null +++ b/source/Asura.Editor/Graphics/Drawer.cpp @@ -0,0 +1,16 @@ +#include "Drawer.h" + +using namespace AEGraphics; + +namespace AsuraEditor +{ + namespace Graphics + { + + void Drawer::DrawImage(Image* img) + { + + } + + } +} \ No newline at end of file diff --git a/source/Asura.Editor/Graphics/Drawer.h b/source/Asura.Editor/Graphics/Drawer.h new file mode 100644 index 0000000..638ce08 --- /dev/null +++ b/source/Asura.Editor/Graphics/Drawer.h @@ -0,0 +1,40 @@ +#ifndef _ASURA_EDITOR_PAINTER_H_ +#define _ASURA_EDITOR_PAINTER_H_ + +#include +#include +#include + +namespace AsuraEditor +{ + namespace Graphics + { + + /// + /// 基于AsuraEngine的渲染部分的绘画类,用于绘制控件和文字。之所以不直接用引擎部分的渲染, + /// 是因为引擎的渲染在framework中实现,有更高级的抽象,而控件的渲染不需要复杂的pass。在 + /// 编辑器下,引擎的渲染和编辑器的渲染可以混编。 + /// + class Drawer + : public AsuraEngine::Singleton + , public AEScripting::Portable + { + public: + + void DrawLine(int x1, int y1, int x2, int y2); + void DrawImage(AEGraphics::Image* img, int x, int y, float sx, float sy, float r, int ox, int oy); + void DrawTexts(); + void DrawCircle(int x, int y, float d); + void DrawPoint(int x, int y); + void DrawPolyline(); + + private: + + LUAX_DECL_SINGLETON(Drawer); + + }; + + } +} + +#endif \ No newline at end of file diff --git a/source/Asura.Editor/Graphics/Pen.cpp b/source/Asura.Editor/Graphics/Pen.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Graphics/Pen.h b/source/Asura.Editor/Graphics/Pen.h new file mode 100644 index 0000000..b949d14 --- /dev/null +++ b/source/Asura.Editor/Graphics/Pen.h @@ -0,0 +1,7 @@ +#ifndef _ASURA_EDITOR_PEN_H_ +#define _ASURA_EDITOR_PEN_H_ + + + + +#endif \ No newline at end of file diff --git a/source/Asura.Editor/Graphics/Shader.h b/source/Asura.Editor/Graphics/Shader.h new file mode 100644 index 0000000..a3abec1 --- /dev/null +++ b/source/Asura.Editor/Graphics/Shader.h @@ -0,0 +1,18 @@ +#ifndef _ASURA_EDITOR_SHADER_H_ +#define _ASURA_EDITOR_SHADER_H_ + +namespace AsuraEditor +{ + namespace Graphics + { + + struct ShaderProgram + { + const char* vert; + const char* frag; + }; + + } +} + +#endif \ No newline at end of file diff --git a/source/Asura.Editor/Graphics/Style.cpp b/source/Asura.Editor/Graphics/Style.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Graphics/Style.h b/source/Asura.Editor/Graphics/Style.h new file mode 100644 index 0000000..b6ed2c5 --- /dev/null +++ b/source/Asura.Editor/Graphics/Style.h @@ -0,0 +1,15 @@ +#ifndef _ASURA_EDITOR_GUI_STYLE_H_ +#define _ASURA_EDITOR_GUI_STYLE_H_ + +#include + +namespace_begin(AsuraEditor) + +class GUIStyle +{ + +}; + +namespace_end + +#endif \ No newline at end of file diff --git a/source/Asura.Editor/Graphics/shaders/image.shader.h b/source/Asura.Editor/Graphics/shaders/image.shader.h new file mode 100644 index 0000000..cbdd542 --- /dev/null +++ b/source/Asura.Editor/Graphics/shaders/image.shader.h @@ -0,0 +1,35 @@ +#ifndef _ASURA_EDITOR_SHADER_H_ +#include "../shader.h" +#endif + +// 绘制 +static AsuraEditor::Graphics::ShaderProgram image_shader = +{ +R"( +in vec2 asura_position; +in vec2 asura_texcoord0; + +uniform mat4 asura_model_matrix; +uniform mat4 asura_view_matrix; +uniform mat4 asura_projection_matrix; + +void main() +{ + gl_Position = asura_projection_matrix * asura_view_matrix * asura_model_matrix * vec4(asura_position, 0, 1); + uv = asura_texcoord0; +} + +)", + +R"( +in vec2 uv; + +uniform sampler2D asura_maintex; + +void main() +{ + +} + +)" +}; \ No newline at end of file diff --git a/source/Asura.Editor/Graphics/shaders/polygon.shader.h b/source/Asura.Editor/Graphics/shaders/polygon.shader.h new file mode 100644 index 0000000..a92e9a6 --- /dev/null +++ b/source/Asura.Editor/Graphics/shaders/polygon.shader.h @@ -0,0 +1,29 @@ +#ifndef _ASURA_EDITOR_SHADER_H_ +#include "../shader.h" +#endif + +// 绘制 +static AsuraEditor::Graphics::ShaderProgram polygon_shader = +{ + R"( +in vec2 position; + +uniform mat4 mvp_matrix; + +void main() +{ + gl_Position = mvp_matrix * vec4(position, 0, 1); +} + +)", + +R"( +uniform vec4 color; + +void main() +{ + gl_FragColor = color; +} + +)" +}; \ No newline at end of file diff --git a/source/Asura.Editor/Layout/HorizontalLayout.cpp b/source/Asura.Editor/Layout/HorizontalLayout.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Layout/HorizontalLayout.h b/source/Asura.Editor/Layout/HorizontalLayout.h new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Layout/VerticalLayout.cpp b/source/Asura.Editor/Layout/VerticalLayout.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Layout/VerticalLayout.h b/source/Asura.Editor/Layout/VerticalLayout.h new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/Main.cpp b/source/Asura.Editor/Main.cpp new file mode 100644 index 0000000..207474b --- /dev/null +++ b/source/Asura.Editor/Main.cpp @@ -0,0 +1,30 @@ +/** + * Copyright (c) 2018-2019 AsuraEngine Team + * + * This software is provided 'as-is', without any express or implied + * warranty. In no event will the authors be held liable for any damages + * arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute it + * freely, subject to the following restrictions: + * + * 1. The origin of this software m_ust not be m_isrepresented; you m_ust not + * claim that you wrote the original software. If you use this software + * in a product, an acknowledgment in the product documentation would be + * appreciated but is not required. + * 2. Altered source versions m_ust be plainly m_arked as such, and m_ust not be + * m_isrepresented as being the original software. + * 3. This notice m_ay not be removed or altered from any source distribution. + **/ + +/// +/// 编辑器的界面通过directUI实现,界面耳朵渲染构建在asura-lib上,事件的响应通过win32API实现。 +/// + +int main(int argn, char* args[]) +{ + + + +} \ No newline at end of file diff --git a/source/Asura.Editor/System/ContainerWindow.cpp b/source/Asura.Editor/System/ContainerWindow.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/System/ContainerWindow.h b/source/Asura.Editor/System/ContainerWindow.h new file mode 100644 index 0000000..ee72b72 --- /dev/null +++ b/source/Asura.Editor/System/ContainerWindow.h @@ -0,0 +1,62 @@ +#ifndef _ASURA_EDITOR_WINDOW_H_ +#define _ASURA_EDITOR_WINDOW_H_ + +#include +#include + +#include +#include + +#include "../Type.h" + +namespace_begin(AsuraEditor) + +/// +/// 包含编辑器窗口的native窗口 +/// +class ContainerWindow : public AEScripting::Portable +{ +public: + + enum WindowStyle + { + WINDOW_STYLE_BASIC, ///< 基础风格 + WINDOW_STYLE_TOOL, ///< 工具栏风格 + WINDOW_STYLE_CONFIRM, ///< 确认窗口 + }; + + struct WindowConfig + { + std::string title; ///< 标题 + uint x, y; ///< 坐标 + uint width, height; ///< 大小 + WindowStyle style; ///< 风格 + }; + + ContainerWindow(); + ~ContainerWindow(); + + bool Init(WindowConfig& config); + +private: + + ContainerWindow* mParent; + WindowStyle mStyle; + HWND mHWND; + HDC mHDC; + +luaxport: + + LUAX_DECL_FACTORY(ContainerWindow); + + LUAX_DECL_ENUM(WindowStyle); + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Init); + LUAX_DECL_METHOD(_SetPosition); + +}; + +namespace_end + +#endif \ No newline at end of file diff --git a/source/Asura.Editor/System/FileWatcher.cpp b/source/Asura.Editor/System/FileWatcher.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/System/FileWatcher.h b/source/Asura.Editor/System/FileWatcher.h new file mode 100644 index 0000000..43821da --- /dev/null +++ b/source/Asura.Editor/System/FileWatcher.h @@ -0,0 +1,517 @@ +// MIT License +// +// Copyright(c) 2017 Thomas Monkman +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files(the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions : +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#ifndef FILEWATCHER_H +#define FILEWATCHER_H + +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#include +#include +#include +#include +#include +#include +#endif // WIN32 + +#if __unix__ +#include +#include +#include +#include +#include +#include +#include +#endif // __unix__ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace filewatch { + enum class Event { + added, + removed, + modified, + renamed_old, + renamed_new + }; + + /** + * \class FileWatch + * + * \brief Watches a folder or file, and will notify of changes via function callback. + * + * \author Thomas Monkman + * + */ + template + class FileWatch + { + typedef std::basic_string> UnderpinningString; + typedef std::basic_regex> UnderpinningRegex; + + public: + + FileWatch(T path, UnderpinningRegex pattern, std::function callback) : + _path(path), + _pattern(pattern), + _callback(callback), + _directory(get_directory(path)) + { + init(); + } + +#if defined _WIN32 && (defined UNICODE || defined _UNICODE) + FileWatch(T path, std::function callback) : + FileWatch(path, UnderpinningRegex(L".*"), callback) {} +#else // _WIN32 && (UNICODE || _UNICODE) + FileWatch(T path, std::function callback) : + FileWatch(path, UnderpinningRegex(".*"), callback) {} +#endif + + ~FileWatch() { + destroy(); + } + + FileWatch(const FileWatch& other) : FileWatch(other._path, other._callback) {} + + FileWatch& operator=(const FileWatch& other) + { + if (this == &other) { return *this; } + + destroy(); + _path = other._path; + _callback = other._callback; + _directory = get_directory(other._path); + init(); + return *this; + } + + // Const memeber varibles don't let me implent moves nicely, if moves are really wanted std::unique_ptr should be used and move that. + FileWatch(FileWatch&&) = delete; + FileWatch& operator=(FileWatch&&) & = delete; + + private: + struct PathParts + { + PathParts(T directory, T filename) : directory(directory), filename(filename) {} + T directory; + T filename; + }; + const T _path; + + UnderpinningRegex _pattern; + + static constexpr std::size_t _buffer_size = { 1024 * 256 }; + + // only used if watch a single file + bool _watching_single_file = { false }; + T _filename; + + std::atomic _destory = { false }; + std::function _callback; + + std::thread _watch_thread; + + std::condition_variable _cv; + std::mutex _callback_mutex; + std::vector> _callback_information; + std::thread _callback_thread; + + std::promise _running; +#ifdef _WIN32 + HANDLE _directory = { nullptr }; + HANDLE _close_event = { nullptr }; + + const DWORD _listen_filters = + FILE_NOTIFY_CHANGE_SECURITY | + FILE_NOTIFY_CHANGE_CREATION | + FILE_NOTIFY_CHANGE_LAST_ACCESS | + FILE_NOTIFY_CHANGE_LAST_WRITE | + FILE_NOTIFY_CHANGE_SIZE | + FILE_NOTIFY_CHANGE_ATTRIBUTES | + FILE_NOTIFY_CHANGE_DIR_NAME | + FILE_NOTIFY_CHANGE_FILE_NAME; + + const std::map _event_type_mapping = { + { FILE_ACTION_ADDED, Event::added }, + { FILE_ACTION_REMOVED, Event::removed }, + { FILE_ACTION_MODIFIED, Event::modified }, + { FILE_ACTION_RENAMED_OLD_NAME, Event::renamed_old }, + { FILE_ACTION_RENAMED_NEW_NAME, Event::renamed_new } + }; +#endif // WIN32 + +#if __unix__ + struct FolderInfo { + int folder; + int watch; + }; + + FolderInfo _directory; + + const std::uint32_t _listen_filters = IN_MODIFY | IN_CREATE | IN_DELETE; + + const static std::size_t event_size = (sizeof(struct inotify_event)); +#endif // __unix__ + + void init() + { +#ifdef _WIN32 + _close_event = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!_close_event) { + throw std::system_error(GetLastError(), std::system_category()); + } +#endif // WIN32 + _callback_thread = std::move(std::thread([this]() { + try { + callback_thread(); + } + catch (...) { + try { + _running.set_exception(std::current_exception()); + } + catch (...) {} // set_exception() may throw too + } + })); + _watch_thread = std::move(std::thread([this]() { + try { + monitor_directory(); + } + catch (...) { + try { + _running.set_exception(std::current_exception()); + } + catch (...) {} // set_exception() may throw too + } + })); + + std::future future = _running.get_future(); + future.get(); //block until the monitor_directory is up and running + } + + void destroy() + { + _destory = true; + _running = std::promise(); +#ifdef _WIN32 + SetEvent(_close_event); +#elif __unix__ + inotify_rm_watch(_directory.folder, _directory.watch); +#endif // __unix__ + _cv.notify_all(); + _watch_thread.join(); + _callback_thread.join(); +#ifdef _WIN32 + CloseHandle(_directory); +#elif __unix__ + close(_directory.folder); +#endif // __unix__ + } + + const PathParts split_directory_and_file(const T& path) const + { + const auto predict = [](typename T::value_type character) { +#ifdef _WIN32 + return character == _T('\\') || character == _T('/'); +#elif __unix__ + return character == '/'; +#endif // __unix__ + }; +#ifdef _WIN32 +#define _UNICODE + const UnderpinningString this_directory = _T("./"); +#elif __unix__ + const UnderpinningString this_directory = "./"; +#endif // __unix__ + + const auto pivot = std::find_if(path.rbegin(), path.rend(), predict).base(); + //if the path is something like "test.txt" there will be no directoy part, however we still need one, so insert './' + const T directory = [&]() { + const auto extracted_directory = UnderpinningString(path.begin(), pivot); + return (extracted_directory.size() > 0) ? extracted_directory : this_directory; + }(); + const T filename = UnderpinningString(pivot, path.end()); + return PathParts(directory, filename); + } + + bool pass_filter(const UnderpinningString& file_path) + { + if (_watching_single_file) { + const UnderpinningString extracted_filename = { split_directory_and_file(file_path).filename }; + //if we are watching a single file, only that file should trigger action + return extracted_filename == _filename; + } + return std::regex_match(file_path, _pattern); + } + +#ifdef _WIN32 + HANDLE get_directory(const T& path) + { + auto file_info = GetFileAttributes(path.c_str()); + + if (file_info == INVALID_FILE_ATTRIBUTES) + { + throw std::system_error(GetLastError(), std::system_category()); + } + _watching_single_file = (file_info & FILE_ATTRIBUTE_DIRECTORY) == false; + + const T watch_path = [this, &path]() { + if (_watching_single_file) + { + const auto parsed_path = split_directory_and_file(path); + _filename = parsed_path.filename; + return parsed_path.directory; + } + else + { + return path; + } + }(); + + HANDLE directory = ::CreateFile( + watch_path.c_str(), // pointer to the file name + FILE_LIST_DIRECTORY, // access (read/write) mode + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, // share mode + NULL, // security descriptor + OPEN_EXISTING, // how to create + FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, // file attributes + NULL); // file with attributes to copy + + if (directory == INVALID_HANDLE_VALUE) + { + throw std::system_error(GetLastError(), std::system_category()); + } + return directory; + } + void monitor_directory() + { + std::vector buffer(_buffer_size); + DWORD bytes_returned = 0; + OVERLAPPED overlapped_buffer{ 0 }; + + overlapped_buffer.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + if (!overlapped_buffer.hEvent) { + std::cerr << "Error creating monitor event" << std::endl; + } + + std::array handles{ overlapped_buffer.hEvent, _close_event }; + + auto async_pending = false; + _running.set_value(); + do { + std::vector> parsed_information; + ReadDirectoryChangesW( + _directory, + buffer.data(), buffer.size(), + TRUE, + _listen_filters, + &bytes_returned, + &overlapped_buffer, NULL); + + async_pending = true; + + switch (WaitForMultipleObjects(2, handles.data(), FALSE, INFINITE)) + { + case WAIT_OBJECT_0: + { + if (!GetOverlappedResult(_directory, &overlapped_buffer, &bytes_returned, TRUE)) { + throw std::system_error(GetLastError(), std::system_category()); + } + async_pending = false; + + if (bytes_returned == 0) { + break; + } + + FILE_NOTIFY_INFORMATION *file_information = reinterpret_cast(&buffer[0]); + do + { + UnderpinningString changed_file{ file_information->FileName, file_information->FileNameLength / 2 }; + if (pass_filter(changed_file)) + { + parsed_information.emplace_back(T{ changed_file }, _event_type_mapping.at(file_information->Action)); + } + + if (file_information->NextEntryOffset == 0) { + break; + } + + file_information = reinterpret_cast(reinterpret_cast(file_information) + file_information->NextEntryOffset); + } while (true); + break; + } + case WAIT_OBJECT_0 + 1: + // quit + break; + case WAIT_FAILED: + break; + } + //dispatch callbacks + { + std::lock_guard lock(_callback_mutex); + _callback_information.insert(_callback_information.end(), parsed_information.begin(), parsed_information.end()); + } + _cv.notify_all(); + } while (_destory == false); + + if (async_pending) + { + //clean up running async io + CancelIo(_directory); + GetOverlappedResult(_directory, &overlapped_buffer, &bytes_returned, TRUE); + } + } +#endif // WIN32 + +#if __unix__ + + bool is_file(const T& path) const + { + struct stat statbuf = {}; + if (stat(path.c_str(), &statbuf) != 0) + { + throw std::system_error(errno, std::system_category()); + } + return S_ISREG(statbuf.st_mode); + } + + FolderInfo get_directory(const T& path) + { + const auto folder = inotify_init(); + if (folder < 0) + { + throw std::system_error(errno, std::system_category()); + } + const auto listen_filters = _listen_filters; + + _watching_single_file = is_file(path); + + const T watch_path = [this, &path]() { + if (_watching_single_file) + { + const auto parsed_path = split_directory_and_file(path); + _filename = parsed_path.filename; + return parsed_path.directory; + } + else + { + return path; + } + }(); + + const auto watch = inotify_add_watch(folder, watch_path.c_str(), IN_MODIFY | IN_CREATE | IN_DELETE); + if (watch < 0) + { + throw std::system_error(errno, std::system_category()); + } + return { folder, watch }; + } + + void monitor_directory() + { + std::vector buffer(_buffer_size); + + _running.set_value(); + while (_destory == false) + { + const auto length = read(_directory.folder, static_cast(buffer.data()), buffer.size()); + if (length > 0) + { + int i = 0; + std::vector> parsed_information; + while (i < length) + { + struct inotify_event *event = reinterpret_cast(&buffer[i]); // NOLINT + if (event->len) + { + const UnderpinningString changed_file{ event->name }; + if (pass_filter(changed_file)) + { + if (event->mask & IN_CREATE) + { + parsed_information.emplace_back(T{ changed_file }, Event::added); + } + else if (event->mask & IN_DELETE) + { + parsed_information.emplace_back(T{ changed_file }, Event::removed); + } + else if (event->mask & IN_MODIFY) + { + parsed_information.emplace_back(T{ changed_file }, Event::modified); + } + } + } + i += event_size + event->len; + } + //dispatch callbacks + { + std::lock_guard lock(_callback_mutex); + _callback_information.insert(_callback_information.end(), parsed_information.begin(), parsed_information.end()); + } + _cv.notify_all(); + } + } + } +#endif // __unix__ + + void callback_thread() + { + while (_destory == false) { + std::unique_lock lock(_callback_mutex); + if (_callback_information.empty() && _destory == false) { + _cv.wait(lock, [this] { return _callback_information.size() > 0 || _destory; }); + } + decltype(_callback_information) callback_information = {}; + std::swap(callback_information, _callback_information); + lock.unlock(); + + for (const auto& file : callback_information) { + if (_callback) { + try + { + _callback(file.first, file.second); + } + catch (const std::exception&) + { + } + } + } + } + } + }; +} +#endif \ No newline at end of file diff --git a/source/Asura.Editor/System/MenuController.cpp b/source/Asura.Editor/System/MenuController.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/Asura.Editor/System/MenuController.h b/source/Asura.Editor/System/MenuController.h new file mode 100644 index 0000000..591cbd9 --- /dev/null +++ b/source/Asura.Editor/System/MenuController.h @@ -0,0 +1,15 @@ +#ifndef _ASURA_EDITOR_MENU_CONTROLLER_H_ +#define _ASURA_EDITOR_MENU_CONTROLLER_H_ + +#include + +namespace_begin(AsuraEditor) + +struct MenuItem; + + + + +namespace_end + +#endif diff --git a/source/Asura.Editor/Type.h b/source/Asura.Editor/Type.h new file mode 100644 index 0000000..f21b376 --- /dev/null +++ b/source/Asura.Editor/Type.h @@ -0,0 +1,30 @@ +#ifndef _ASURA_EDITOR_TYPE_H_ +#define _ASURA_EDITOR_TYPE_H_ + +#include +#include + +namespace AsuraEditor +{ + + typedef int8_t int8; + typedef uint8_t uint8; + //typedef uint8 byte; + typedef char byte; + typedef int16_t int16; + typedef uint16_t uint16; + typedef int32_t int32; + typedef uint32_t uint32; + typedef int64_t int64; + typedef uint64_t uint64; + + typedef uint32_t uint; + typedef int32_t sint; + + typedef std::size_t size_t; + + typedef const char cc8; + +} + +#endif \ No newline at end of file diff --git a/source/Asura.Editor/controls/button.cpp b/source/Asura.Editor/controls/button.cpp deleted file mode 100644 index c5741c1..0000000 --- a/source/Asura.Editor/controls/button.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "gui_button.h" - -namespace_begin(AsuraEditor) - - - - -namespace_end diff --git a/source/Asura.Editor/controls/button.h b/source/Asura.Editor/controls/button.h deleted file mode 100644 index edfa7b7..0000000 --- a/source/Asura.Editor/controls/button.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __ASURA_EDITOR_GUI_BUTTON_H__ -#define __ASURA_EDITOR_GUI_BUTTON_H__ - -#include - -namespace_begin(AsuraEditor) - -bool Button(); - - - -namespace_end - -#endif diff --git a/source/Asura.Editor/controls/content.cpp b/source/Asura.Editor/controls/content.cpp deleted file mode 100644 index c5741c1..0000000 --- a/source/Asura.Editor/controls/content.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "gui_button.h" - -namespace_begin(AsuraEditor) - - - - -namespace_end diff --git a/source/Asura.Editor/controls/content.h b/source/Asura.Editor/controls/content.h deleted file mode 100644 index 230bfa9..0000000 --- a/source/Asura.Editor/controls/content.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __ASURA_EDITOR_GUI_BUTTON_H__ -#define __ASURA_EDITOR_GUI_BUTTON_H__ - -#include - -namespace_begin(AsuraEditor) - -/// IMGUI content -class Content -{ - -}; - - -namespace_end - -#endif diff --git a/source/Asura.Editor/controls/label.cpp b/source/Asura.Editor/controls/label.cpp deleted file mode 100644 index c5741c1..0000000 --- a/source/Asura.Editor/controls/label.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "gui_button.h" - -namespace_begin(AsuraEditor) - - - - -namespace_end diff --git a/source/Asura.Editor/controls/label.h b/source/Asura.Editor/controls/label.h deleted file mode 100644 index 7cc6e3d..0000000 --- a/source/Asura.Editor/controls/label.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __ASURA_EDITOR_GUI_BUTTON_H__ -#define __ASURA_EDITOR_GUI_BUTTON_H__ - -#include - -namespace_begin(AsuraEditor) - -bool Label(); - - - -namespace_end - -#endif diff --git a/source/Asura.Editor/controls/panel.cpp b/source/Asura.Editor/controls/panel.cpp deleted file mode 100644 index 2e6e2cc..0000000 --- a/source/Asura.Editor/controls/panel.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "gui_button.h" - -namespace_begin(AsuraEditor) - -class GUIWindow -{ -public: - - GUIWindow(); - ~GUIWindow(); - -}; - - - -namespace_end diff --git a/source/Asura.Editor/controls/panel.h b/source/Asura.Editor/controls/panel.h deleted file mode 100644 index b485635..0000000 --- a/source/Asura.Editor/controls/panel.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __ASURA_EDITOR_GUI_BUTTON_H__ -#define __ASURA_EDITOR_GUI_BUTTON_H__ - -#include - -namespace_begin(AsuraEditor) - -/// IMGUI panel -class Panel -{ - -}; - -namespace_end - -#endif diff --git a/source/Asura.Editor/controls/toggle.cpp b/source/Asura.Editor/controls/toggle.cpp deleted file mode 100644 index 40d2043..0000000 --- a/source/Asura.Editor/controls/toggle.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "gui_button.h" - -namespace_begin(AsuraEditor) - -bool GUIToggle(); - - -namespace_end diff --git a/source/Asura.Editor/controls/toggle.h b/source/Asura.Editor/controls/toggle.h deleted file mode 100644 index 19e9379..0000000 --- a/source/Asura.Editor/controls/toggle.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __ASURA_EDITOR_GUI_BUTTON_H__ -#define __ASURA_EDITOR_GUI_BUTTON_H__ - -#include - -namespace_begin(AsuraEditor) - -bool Toggle(); - - - -namespace_end - -#endif diff --git a/source/Asura.Editor/core/gui_state.h b/source/Asura.Editor/core/gui_state.h deleted file mode 100644 index 9e7e91c..0000000 --- a/source/Asura.Editor/core/gui_state.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _ASURA_EDITOR_GUI_STATE_H_ -#define _ASURA_EDITOR_GUI_STATE_H_ - -#include - -namespace_begin(AsuraEditor) - -/// GUI widgets uniqueID - - - - -namespace_end - - -#endif - diff --git a/source/Asura.Editor/editor.h b/source/Asura.Editor/editor.h index fbcfb62..2f5f8ca 100644 --- a/source/Asura.Editor/editor.h +++ b/source/Asura.Editor/editor.h @@ -1,7 +1,7 @@ -#ifndef __ASURA_EDITOR_H__ -#define __ASURA_EDITOR_H__ +#ifndef _ASURA_EDITOR_H_ +#define _ASURA_EDITOR_H_ -#include +#include namespace AsuraEditor { diff --git a/source/Asura.Editor/graphics/brush.h b/source/Asura.Editor/graphics/brush.h index 5ffdba4..4290926 100644 --- a/source/Asura.Editor/graphics/brush.h +++ b/source/Asura.Editor/graphics/brush.h @@ -1,5 +1,5 @@ -#ifndef __ASURA_EDITOR_BRUSH_H__ -#define __ASURA_EDITOR_BRUSH_H__ +#ifndef _ASURA_EDITOR_BRUSH_H_ +#define _ASURA_EDITOR_BRUSH_H_ namespace AsuraEditor { diff --git a/source/Asura.Editor/graphics/draw_info.cpp b/source/Asura.Editor/graphics/draw_info.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/Asura.Editor/graphics/draw_info.h b/source/Asura.Editor/graphics/draw_info.h deleted file mode 100644 index 442b92d..0000000 --- a/source/Asura.Editor/graphics/draw_info.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __ASURA_EDITOR_DRAW_INFO_H__ -#define __ASURA_EDITOR_DRAW_INFO_H__ - -namespace AsuraEditor -{ - namespace Graphics - { - - - - } -} - -#endif \ No newline at end of file diff --git a/source/Asura.Editor/graphics/drawer.cpp b/source/Asura.Editor/graphics/drawer.cpp index f2fca31..6482aeb 100644 --- a/source/Asura.Editor/graphics/drawer.cpp +++ b/source/Asura.Editor/graphics/drawer.cpp @@ -1,4 +1,4 @@ -#include "drawer.h" +#include "Drawer.h" using namespace AEGraphics; diff --git a/source/Asura.Editor/graphics/drawer.h b/source/Asura.Editor/graphics/drawer.h index 85cc88a..638ce08 100644 --- a/source/Asura.Editor/graphics/drawer.h +++ b/source/Asura.Editor/graphics/drawer.h @@ -1,9 +1,9 @@ -#ifndef __ASURA_EDITOR_PAINTER_H__ -#define __ASURA_EDITOR_PAINTER_H__ +#ifndef _ASURA_EDITOR_PAINTER_H_ +#define _ASURA_EDITOR_PAINTER_H_ -#include -#include -#include +#include +#include +#include namespace AsuraEditor { diff --git a/source/Asura.Editor/graphics/pen.h b/source/Asura.Editor/graphics/pen.h index 87a031c..b949d14 100644 --- a/source/Asura.Editor/graphics/pen.h +++ b/source/Asura.Editor/graphics/pen.h @@ -1,20 +1,7 @@ -#ifndef __ASURA_EDITOR_PEN_H__ -#define __ASURA_EDITOR_PEN_H__ +#ifndef _ASURA_EDITOR_PEN_H_ +#define _ASURA_EDITOR_PEN_H_ -namespace AsuraEditor -{ - namespace Graphics - { - /// - /// 画笔,用来指定绘制的线条格式 - /// - class Pen - { - }; - - } -} #endif \ No newline at end of file diff --git a/source/Asura.Editor/graphics/shader.h b/source/Asura.Editor/graphics/shader.h index 6f5a8cc..a3abec1 100644 --- a/source/Asura.Editor/graphics/shader.h +++ b/source/Asura.Editor/graphics/shader.h @@ -1,5 +1,5 @@ -#ifndef __ASURA_EDITOR_SHADER_H__ -#define __ASURA_EDITOR_SHADER_H__ +#ifndef _ASURA_EDITOR_SHADER_H_ +#define _ASURA_EDITOR_SHADER_H_ namespace AsuraEditor { diff --git a/source/Asura.Editor/graphics/shaders/image.shader.h b/source/Asura.Editor/graphics/shaders/image.shader.h index ee6be43..cbdd542 100644 --- a/source/Asura.Editor/graphics/shaders/image.shader.h +++ b/source/Asura.Editor/graphics/shaders/image.shader.h @@ -1,4 +1,4 @@ -#ifndef __ASURA_EDITOR_SHADER_H__ +#ifndef _ASURA_EDITOR_SHADER_H_ #include "../shader.h" #endif diff --git a/source/Asura.Editor/graphics/shaders/polygon.shader.h b/source/Asura.Editor/graphics/shaders/polygon.shader.h index eed4f5a..a92e9a6 100644 --- a/source/Asura.Editor/graphics/shaders/polygon.shader.h +++ b/source/Asura.Editor/graphics/shaders/polygon.shader.h @@ -1,4 +1,4 @@ -#ifndef __ASURA_EDITOR_SHADER_H__ +#ifndef _ASURA_EDITOR_SHADER_H_ #include "../shader.h" #endif diff --git a/source/Asura.Editor/graphics/slider.cpp b/source/Asura.Editor/graphics/slider.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/Asura.Editor/graphics/slider.h b/source/Asura.Editor/graphics/slider.h deleted file mode 100644 index 28ea77f..0000000 --- a/source/Asura.Editor/graphics/slider.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __ASURA_EDITOR_GUI_SLIDER_H__ -#define __ASURA_EDITOR_GUI_SLIDER_H__ - -#include - -namespace_begin(AsuraEditor) - -void Slider(); - - -namespace_end - - -#endif diff --git a/source/Asura.Editor/graphics/style.h b/source/Asura.Editor/graphics/style.h index fca3c37..b6ed2c5 100644 --- a/source/Asura.Editor/graphics/style.h +++ b/source/Asura.Editor/graphics/style.h @@ -1,11 +1,11 @@ -#ifndef __ASURA_EDITOR_GUI_STYLE_H__ -#define __ASURA_EDITOR_GUI_STYLE_H__ +#ifndef _ASURA_EDITOR_GUI_STYLE_H_ +#define _ASURA_EDITOR_GUI_STYLE_H_ -#include +#include namespace_begin(AsuraEditor) -class Style +class GUIStyle { }; diff --git a/source/Asura.Editor/layout/horizontal_layout.cpp b/source/Asura.Editor/layout/horizontal_layout.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/Asura.Editor/layout/horizontal_layout.h b/source/Asura.Editor/layout/horizontal_layout.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/Asura.Editor/layout/vertical_layout.cpp b/source/Asura.Editor/layout/vertical_layout.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/Asura.Editor/layout/vertical_layout.h b/source/Asura.Editor/layout/vertical_layout.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/Asura.Editor/main.cpp b/source/Asura.Editor/main.cpp index ed055cf..207474b 100644 --- a/source/Asura.Editor/main.cpp +++ b/source/Asura.Editor/main.cpp @@ -9,13 +9,13 @@ * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * - * 1. The origin of this software must not be misrepresented; you must not + * 1. The origin of this software m_ust not be m_isrepresented; you m_ust not * claim that you wrote the original software. If you use this software * in a product, an acknowledgment in the product documentation would be * appreciated but is not required. - * 2. Altered source versions must be plainly marked as such, and must not be - * misrepresented as being the original software. - * 3. This notice may not be removed or altered from any source distribution. + * 2. Altered source versions m_ust be plainly m_arked as such, and m_ust not be + * m_isrepresented as being the original software. + * 3. This notice m_ay not be removed or altered from any source distribution. **/ /// diff --git a/source/Asura.Editor/system/editor_window.cpp b/source/Asura.Editor/system/editor_window.cpp deleted file mode 100644 index 0e2d4f4..0000000 --- a/source/Asura.Editor/system/editor_window.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "editor_window.h" - -namespace AsuraEditor -{ - -} // AsruaEditor \ No newline at end of file diff --git a/source/Asura.Editor/system/editor_window.h b/source/Asura.Editor/system/editor_window.h deleted file mode 100644 index 50c9cb3..0000000 --- a/source/Asura.Editor/system/editor_window.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef __ASURA_EDITOR_WINDOW_H__ -#define __ASURA_EDITOR_WINDOW_H__ - -#include -#include - -#include - -#include "../type.h" - -namespace AsuraEditor -{ - - /// - /// 包含编辑器窗口的native窗口 - /// - class ContainerWindow : public AEScripting::Portable - { - public: - - enum WindowStyle - { - WINDOW_STYLE_BASIC, ///< 基础风格 - WINDOW_STYLE_TOOL, ///< 工具栏风格 - WINDOW_STYLE_CONFIRM, ///< 确认窗口 - }; - - struct WindowConfig - { - std::string title; ///< 标题 - uint x, y; ///< 坐标 - uint width, height; ///< 大小 - WindowStyle style; ///< 风格 - }; - - ContainerWindow(); - ~ContainerWindow(); - - bool Init(WindowConfig& config); - - private: - - ContainerWindow* mParent; - WindowStyle mStyle; - HWND mHWND; - HDC mHDC; - - luaxport: - - LUAX_DECL_FACTORY(ContainerWindow); - - LUAX_DECL_ENUM(WindowStyle); - - LUAX_DECL_METHOD(_New); - LUAX_DECL_METHOD(_Init); - LUAX_DECL_METHOD(_SetPosition); - - }; - -} // AsuraEditor - -#endif \ No newline at end of file diff --git a/source/Asura.Editor/system/file_watcher.cpp b/source/Asura.Editor/system/file_watcher.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/Asura.Editor/system/file_watcher.h b/source/Asura.Editor/system/file_watcher.h deleted file mode 100644 index 43821da..0000000 --- a/source/Asura.Editor/system/file_watcher.h +++ /dev/null @@ -1,517 +0,0 @@ -// MIT License -// -// Copyright(c) 2017 Thomas Monkman -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files(the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions : -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -#ifndef FILEWATCHER_H -#define FILEWATCHER_H - -#ifdef _WIN32 -#define WIN32_LEAN_AND_MEAN -#define NOMINMAX -#include -#include -#include -#include -#include -#include -#endif // WIN32 - -#if __unix__ -#include -#include -#include -#include -#include -#include -#include -#endif // __unix__ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace filewatch { - enum class Event { - added, - removed, - modified, - renamed_old, - renamed_new - }; - - /** - * \class FileWatch - * - * \brief Watches a folder or file, and will notify of changes via function callback. - * - * \author Thomas Monkman - * - */ - template - class FileWatch - { - typedef std::basic_string> UnderpinningString; - typedef std::basic_regex> UnderpinningRegex; - - public: - - FileWatch(T path, UnderpinningRegex pattern, std::function callback) : - _path(path), - _pattern(pattern), - _callback(callback), - _directory(get_directory(path)) - { - init(); - } - -#if defined _WIN32 && (defined UNICODE || defined _UNICODE) - FileWatch(T path, std::function callback) : - FileWatch(path, UnderpinningRegex(L".*"), callback) {} -#else // _WIN32 && (UNICODE || _UNICODE) - FileWatch(T path, std::function callback) : - FileWatch(path, UnderpinningRegex(".*"), callback) {} -#endif - - ~FileWatch() { - destroy(); - } - - FileWatch(const FileWatch& other) : FileWatch(other._path, other._callback) {} - - FileWatch& operator=(const FileWatch& other) - { - if (this == &other) { return *this; } - - destroy(); - _path = other._path; - _callback = other._callback; - _directory = get_directory(other._path); - init(); - return *this; - } - - // Const memeber varibles don't let me implent moves nicely, if moves are really wanted std::unique_ptr should be used and move that. - FileWatch(FileWatch&&) = delete; - FileWatch& operator=(FileWatch&&) & = delete; - - private: - struct PathParts - { - PathParts(T directory, T filename) : directory(directory), filename(filename) {} - T directory; - T filename; - }; - const T _path; - - UnderpinningRegex _pattern; - - static constexpr std::size_t _buffer_size = { 1024 * 256 }; - - // only used if watch a single file - bool _watching_single_file = { false }; - T _filename; - - std::atomic _destory = { false }; - std::function _callback; - - std::thread _watch_thread; - - std::condition_variable _cv; - std::mutex _callback_mutex; - std::vector> _callback_information; - std::thread _callback_thread; - - std::promise _running; -#ifdef _WIN32 - HANDLE _directory = { nullptr }; - HANDLE _close_event = { nullptr }; - - const DWORD _listen_filters = - FILE_NOTIFY_CHANGE_SECURITY | - FILE_NOTIFY_CHANGE_CREATION | - FILE_NOTIFY_CHANGE_LAST_ACCESS | - FILE_NOTIFY_CHANGE_LAST_WRITE | - FILE_NOTIFY_CHANGE_SIZE | - FILE_NOTIFY_CHANGE_ATTRIBUTES | - FILE_NOTIFY_CHANGE_DIR_NAME | - FILE_NOTIFY_CHANGE_FILE_NAME; - - const std::map _event_type_mapping = { - { FILE_ACTION_ADDED, Event::added }, - { FILE_ACTION_REMOVED, Event::removed }, - { FILE_ACTION_MODIFIED, Event::modified }, - { FILE_ACTION_RENAMED_OLD_NAME, Event::renamed_old }, - { FILE_ACTION_RENAMED_NEW_NAME, Event::renamed_new } - }; -#endif // WIN32 - -#if __unix__ - struct FolderInfo { - int folder; - int watch; - }; - - FolderInfo _directory; - - const std::uint32_t _listen_filters = IN_MODIFY | IN_CREATE | IN_DELETE; - - const static std::size_t event_size = (sizeof(struct inotify_event)); -#endif // __unix__ - - void init() - { -#ifdef _WIN32 - _close_event = CreateEvent(NULL, TRUE, FALSE, NULL); - if (!_close_event) { - throw std::system_error(GetLastError(), std::system_category()); - } -#endif // WIN32 - _callback_thread = std::move(std::thread([this]() { - try { - callback_thread(); - } - catch (...) { - try { - _running.set_exception(std::current_exception()); - } - catch (...) {} // set_exception() may throw too - } - })); - _watch_thread = std::move(std::thread([this]() { - try { - monitor_directory(); - } - catch (...) { - try { - _running.set_exception(std::current_exception()); - } - catch (...) {} // set_exception() may throw too - } - })); - - std::future future = _running.get_future(); - future.get(); //block until the monitor_directory is up and running - } - - void destroy() - { - _destory = true; - _running = std::promise(); -#ifdef _WIN32 - SetEvent(_close_event); -#elif __unix__ - inotify_rm_watch(_directory.folder, _directory.watch); -#endif // __unix__ - _cv.notify_all(); - _watch_thread.join(); - _callback_thread.join(); -#ifdef _WIN32 - CloseHandle(_directory); -#elif __unix__ - close(_directory.folder); -#endif // __unix__ - } - - const PathParts split_directory_and_file(const T& path) const - { - const auto predict = [](typename T::value_type character) { -#ifdef _WIN32 - return character == _T('\\') || character == _T('/'); -#elif __unix__ - return character == '/'; -#endif // __unix__ - }; -#ifdef _WIN32 -#define _UNICODE - const UnderpinningString this_directory = _T("./"); -#elif __unix__ - const UnderpinningString this_directory = "./"; -#endif // __unix__ - - const auto pivot = std::find_if(path.rbegin(), path.rend(), predict).base(); - //if the path is something like "test.txt" there will be no directoy part, however we still need one, so insert './' - const T directory = [&]() { - const auto extracted_directory = UnderpinningString(path.begin(), pivot); - return (extracted_directory.size() > 0) ? extracted_directory : this_directory; - }(); - const T filename = UnderpinningString(pivot, path.end()); - return PathParts(directory, filename); - } - - bool pass_filter(const UnderpinningString& file_path) - { - if (_watching_single_file) { - const UnderpinningString extracted_filename = { split_directory_and_file(file_path).filename }; - //if we are watching a single file, only that file should trigger action - return extracted_filename == _filename; - } - return std::regex_match(file_path, _pattern); - } - -#ifdef _WIN32 - HANDLE get_directory(const T& path) - { - auto file_info = GetFileAttributes(path.c_str()); - - if (file_info == INVALID_FILE_ATTRIBUTES) - { - throw std::system_error(GetLastError(), std::system_category()); - } - _watching_single_file = (file_info & FILE_ATTRIBUTE_DIRECTORY) == false; - - const T watch_path = [this, &path]() { - if (_watching_single_file) - { - const auto parsed_path = split_directory_and_file(path); - _filename = parsed_path.filename; - return parsed_path.directory; - } - else - { - return path; - } - }(); - - HANDLE directory = ::CreateFile( - watch_path.c_str(), // pointer to the file name - FILE_LIST_DIRECTORY, // access (read/write) mode - FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, // share mode - NULL, // security descriptor - OPEN_EXISTING, // how to create - FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, // file attributes - NULL); // file with attributes to copy - - if (directory == INVALID_HANDLE_VALUE) - { - throw std::system_error(GetLastError(), std::system_category()); - } - return directory; - } - void monitor_directory() - { - std::vector buffer(_buffer_size); - DWORD bytes_returned = 0; - OVERLAPPED overlapped_buffer{ 0 }; - - overlapped_buffer.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - if (!overlapped_buffer.hEvent) { - std::cerr << "Error creating monitor event" << std::endl; - } - - std::array handles{ overlapped_buffer.hEvent, _close_event }; - - auto async_pending = false; - _running.set_value(); - do { - std::vector> parsed_information; - ReadDirectoryChangesW( - _directory, - buffer.data(), buffer.size(), - TRUE, - _listen_filters, - &bytes_returned, - &overlapped_buffer, NULL); - - async_pending = true; - - switch (WaitForMultipleObjects(2, handles.data(), FALSE, INFINITE)) - { - case WAIT_OBJECT_0: - { - if (!GetOverlappedResult(_directory, &overlapped_buffer, &bytes_returned, TRUE)) { - throw std::system_error(GetLastError(), std::system_category()); - } - async_pending = false; - - if (bytes_returned == 0) { - break; - } - - FILE_NOTIFY_INFORMATION *file_information = reinterpret_cast(&buffer[0]); - do - { - UnderpinningString changed_file{ file_information->FileName, file_information->FileNameLength / 2 }; - if (pass_filter(changed_file)) - { - parsed_information.emplace_back(T{ changed_file }, _event_type_mapping.at(file_information->Action)); - } - - if (file_information->NextEntryOffset == 0) { - break; - } - - file_information = reinterpret_cast(reinterpret_cast(file_information) + file_information->NextEntryOffset); - } while (true); - break; - } - case WAIT_OBJECT_0 + 1: - // quit - break; - case WAIT_FAILED: - break; - } - //dispatch callbacks - { - std::lock_guard lock(_callback_mutex); - _callback_information.insert(_callback_information.end(), parsed_information.begin(), parsed_information.end()); - } - _cv.notify_all(); - } while (_destory == false); - - if (async_pending) - { - //clean up running async io - CancelIo(_directory); - GetOverlappedResult(_directory, &overlapped_buffer, &bytes_returned, TRUE); - } - } -#endif // WIN32 - -#if __unix__ - - bool is_file(const T& path) const - { - struct stat statbuf = {}; - if (stat(path.c_str(), &statbuf) != 0) - { - throw std::system_error(errno, std::system_category()); - } - return S_ISREG(statbuf.st_mode); - } - - FolderInfo get_directory(const T& path) - { - const auto folder = inotify_init(); - if (folder < 0) - { - throw std::system_error(errno, std::system_category()); - } - const auto listen_filters = _listen_filters; - - _watching_single_file = is_file(path); - - const T watch_path = [this, &path]() { - if (_watching_single_file) - { - const auto parsed_path = split_directory_and_file(path); - _filename = parsed_path.filename; - return parsed_path.directory; - } - else - { - return path; - } - }(); - - const auto watch = inotify_add_watch(folder, watch_path.c_str(), IN_MODIFY | IN_CREATE | IN_DELETE); - if (watch < 0) - { - throw std::system_error(errno, std::system_category()); - } - return { folder, watch }; - } - - void monitor_directory() - { - std::vector buffer(_buffer_size); - - _running.set_value(); - while (_destory == false) - { - const auto length = read(_directory.folder, static_cast(buffer.data()), buffer.size()); - if (length > 0) - { - int i = 0; - std::vector> parsed_information; - while (i < length) - { - struct inotify_event *event = reinterpret_cast(&buffer[i]); // NOLINT - if (event->len) - { - const UnderpinningString changed_file{ event->name }; - if (pass_filter(changed_file)) - { - if (event->mask & IN_CREATE) - { - parsed_information.emplace_back(T{ changed_file }, Event::added); - } - else if (event->mask & IN_DELETE) - { - parsed_information.emplace_back(T{ changed_file }, Event::removed); - } - else if (event->mask & IN_MODIFY) - { - parsed_information.emplace_back(T{ changed_file }, Event::modified); - } - } - } - i += event_size + event->len; - } - //dispatch callbacks - { - std::lock_guard lock(_callback_mutex); - _callback_information.insert(_callback_information.end(), parsed_information.begin(), parsed_information.end()); - } - _cv.notify_all(); - } - } - } -#endif // __unix__ - - void callback_thread() - { - while (_destory == false) { - std::unique_lock lock(_callback_mutex); - if (_callback_information.empty() && _destory == false) { - _cv.wait(lock, [this] { return _callback_information.size() > 0 || _destory; }); - } - decltype(_callback_information) callback_information = {}; - std::swap(callback_information, _callback_information); - lock.unlock(); - - for (const auto& file : callback_information) { - if (_callback) { - try - { - _callback(file.first, file.second); - } - catch (const std::exception&) - { - } - } - } - } - } - }; -} -#endif \ No newline at end of file diff --git a/source/Asura.Editor/type.h b/source/Asura.Editor/type.h index d58cf87..f21b376 100644 --- a/source/Asura.Editor/type.h +++ b/source/Asura.Editor/type.h @@ -1,5 +1,5 @@ -#ifndef __ASURA_EDITOR_TYPE_H__ -#define __ASURA_EDITOR_TYPE_H__ +#ifndef _ASURA_EDITOR_TYPE_H_ +#define _ASURA_EDITOR_TYPE_H_ #include #include diff --git a/source/external/Luax/luax.h b/source/external/Luax/luax.h index 7a0dcd6..1980f41 100644 --- a/source/external/Luax/luax.h +++ b/source/external/Luax/luax.h @@ -12,7 +12,7 @@ #include "luax_enum.h" #include "luax_class.hpp" #include "luax_memberref.h" -#include "luax_class.inl" -#include "luax_state.inl" +#include "luax_class.inc" +#include "luax_state.inc" #endif \ No newline at end of file diff --git a/source/external/Luax/luax_class.inc b/source/external/Luax/luax_class.inc new file mode 100644 index 0000000..1d6a89f --- /dev/null +++ b/source/external/Luax/luax_class.inc @@ -0,0 +1,637 @@ +namespace Luax +{ + + //--------------------------------------------------------------------------------// + + /// + /// 对不同类型,通过调用GetLuaClassName获得类型名,如果是派生类,GetClassName会被覆盖,指向luax_c_getupvalue。 + /// + template + int LuaxNativeClass::_GetClassName(lua_State* L) + { + LUAX_SETUP(L, "*"); + + cc8* type = TYPE::GetLuaxClassName(); + state.Push(type); + return 1; + } + + //--------------------------------------------------------------------------------// + + /// + /// 注册工厂和单例共有的类成员 + /// + template + void LuaxNativeClass::RegisterLuaxClassShared(LuaxState& state) + { + luaL_Reg regTable[] = { + { "GetClass", _GetClass }, + { "GetClassName", _GetClassName }, + { NULL, NULL } + }; + + state.RegisterMethods(regTable); + } + + /// + /// 工厂类的成员,注册在class table + /// + template + void LuaxNativeClass::RegisterLuaxFactoryClass(LuaxState& state) + { + luaL_Reg regTable[] = { + { "GetRefTable", _GetRefTable }, + { NULL, NULL } + }; + + state.RegisterMethods(regTable); + } + + /// + /// 单例类的成员,注册在class table + /// + template + void LuaxNativeClass::RegisterLuaxSingletonClass(LuaxState& state) + { + luaL_Reg regTable[] = { + { NULL, NULL } + }; + + state.RegisterMethods(regTable); + } + + template + void LuaxNativeClass::PushLuaxClassTable(LuaxState& state) + { + assert(mClassTable); + + mClassTable.PushRef(state); + } + + template + void LuaxNativeClass::SetLuaxClassTableRef(LuaxState& state, int idx) + { + mClassTable.SetRef(state, idx); + } + + template + LuaxNativeClass::LuaxNativeClass() + : mWatchDog() +#if LUAX_PROFILER + , mSafer(false) +#endif + { + } + + template + LuaxNativeClass::~LuaxNativeClass() + { + } + +#if LUAX_PROFILER + template + void LuaxNativeClass::operator delete(void* pdead, size_t size) + { + if (pdead == nullptr) + return; + // 堆上创建的实例必须使用Release释放。 + TYPE* p = static_cast(pdead); + assert(p->mSafer); + ::operator delete(pdead, size); + } +#endif + + template + void LuaxNativeClass::Retain() + { + ++mWatchDog.mNativeRef; + } + + template + void LuaxNativeClass::Release() + { + if (mWatchDog.mNativeRef > 0) + --mWatchDog.mNativeRef; + if (mWatchDog) + { +#if LUAX_PROFILER + mSafer = true; +#endif + delete this; + } + } + + template + template + void LuaxNativeClass::LuaxRetain(LuaxState& state, U* userdata) + { + if (PushLuaxRefTable(state)) + { + if (userdata->PushLuaxUserdata(state)) + { + lua_pushvalue(state, -1); // copy the userdata + lua_gettable(state, -3); // get the count (or nil) + u32 count = state.GetValue(-1, 0); // get the count (or 0) + lua_pop(state, 1); // pop the old count + lua_pushnumber(state, count + 1); // push the new count + lua_settable(state, -3); // save it in the table: reftable[userdata] = count + } + } + } + + template + template + void LuaxNativeClass::LuaxRelease(LuaxState& state, U* userdata) + { + if (PushLuaxRefTable(state)) + { + if (userdata->PushLuaxUserdata(state)) + { + lua_pushvalue(state, -1); // copy the userdata + lua_gettable(state, -3); // get the count (or nil) + u32 count = state.GetValue(-1, 0); // get the count (or 0) + lua_pop(state, 1); // pop the old count + + // no such reference + if (count == 0) + { + state.Pop(2); // userdata, reftable + return; // nothing to do + } + + if (count > 1) { + lua_pushnumber(state, count - 1); // push the new count + } + else { + lua_pushnil(state); // maybe cause gc + } + lua_settable(state, -3); // save it in the table + + state.Pop(1); // reftable + return; + } + state.Pop(2); // nil, reftable + return; + } + } + + template + bool LuaxNativeClass::PushLuaxUserdata(LuaxState& state) + { + assert(!TYPE::IsLuaxClassSingleton()); + if (!mUserdata) + { + BindToLua(state); + return true; + } + return mUserdata.PushRef(state); + } + + template + bool LuaxNativeClass::PushLuaxMemberTable(LuaxState& state) + { + int top = state.GetTop(); + if (this->PushLuaxUserdata(state)) + { + if (lua_getmetatable(state, -1)) // ref table + { + lua_replace(state, -2); + if (lua_getmetatable(state, -1)) // member table + { + lua_replace(state, -2); + return true; + } + } + } + lua_settop(state, top); + lua_pushnil(state); + return false; + } + + template + bool LuaxNativeClass::PushLuaxRefTable(LuaxState& state) + { + // Singleton + if (TYPE::IsLuaxClassSingleton()) + { + if (!this->mSingletonRefTable) { + lua_newtable(state); + this->mSingletonRefTable.SetRef(state, -1); // strong ref to member table won't be garbage collected + } + else { + this->mSingletonRefTable.PushRef(state); + } + return true; + } + // Factory + else + { + if (this->PushLuaxUserdata(state)) + { + if (lua_getmetatable(state, -1)) + { + lua_replace(state, -2); + return true; + } + } + } + return false; + } + + /// + /// 创建userdata,并以此添加ref table,member table和class table。 + /// ref table 是kv强引用table,保存对其他userdata的引用计数(通过userdata作为key, + /// 计数为value),以及成员引用 + /// member table 保存lua创建的实例的成员 + /// class table 所有本类型的实例共有的函数表 + /// + /// BindToLua只会在第一次注册给Lua虚拟机时调用。 + /// + template + void LuaxNativeClass::BindToLua(LuaxState& state) + { + // 单例不能绑定userdata + assert(!TYPE::IsLuaxClassSingleton()); + assert(!mUserdata); + + /// + /// 创建userdata并留在栈顶,注意地址要转换为TYPE*,直接用this可能会导致多重继承的类丧失多态。 + /// 如果直接传this进去,在多重继承情况下,是拿不到另一头的虚函数表的。所以这里需要将this + /// 转换为整个对象的低地址,这样可以拿到另一个基类的虚函数表,通过另一个基类实现多态。 + /// + TYPE* p = static_cast(this); + state.PushPtrUserdata(p); + + lua_newtable(state); // ref table,无法在lua处访问,用来管理C对象的生命周期 + lua_newtable(state); // member table,lua中创建的对象成员都保存在这里 + PushLuaxClassTable(state); // class table + + // stack: + // -1: class table + // -2: member table + // -3: ref table + // -4: userdata + + int top = state.GetTop(); + int memberTable = top - 1; + int refTable = top - 2; + + // ref table 注册 __tostring 和 __gc + lua_pushcfunction(state, __tostring); + lua_setfield(state, refTable, "__tostring"); + + lua_pushcfunction(state, __gc); + lua_setfield(state, refTable, "__gc"); + + // ref table 的 __index 和 __newindex 设为 member table + lua_pushvalue(state, memberTable); + lua_setfield(state, refTable, "__index"); + + lua_pushvalue(state, memberTable); + lua_setfield(state, refTable, "__newindex"); + + // 设置元表 + lua_setmetatable(state, -2); // class is meta of member + lua_setmetatable(state, -2); // member is meta of ref + lua_setmetatable(state, -2); // ref is meta of userdata + + // 设置一个userdata的弱引用,方便通过PushLuaUserdata方法返回lua对象 + mUserdata.SetRef(state, -1); + assert(mUserdata); + + // 增加一个虚拟机引用,在GC时-1 + ++mWatchDog.mVMRef; +#if LUAX_PROFILER + mRefVMs.insert(state.GetVM()); +#endif + } + + /// + /// 成员引用管理 + /// + template + void LuaxNativeClass::SetLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx) + { + ClearLuaxMemberRef(state, memRef); + if (!lua_isnil(state, idx)) + { + idx = state.AbsIndex(idx); + if (PushLuaxRefTable(state)) + { + lua_pushvalue(state, idx); + memRef.refID = luaL_ref(state, -2); + state.Pop(); // ref table + } + } + } + + template + bool LuaxNativeClass::PushLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef) + { + if (memRef) + { + if (PushLuaxRefTable(state)) + { + lua_rawgeti(state, -1, memRef.refID); + lua_replace(state, -2); // ref table + if (lua_isnil(state, -1)) + goto failed; + return true; + } + } + lua_pushnil(state); + failed: + memRef.refID = LUA_NOREF; + return false; + } + + template + bool LuaxNativeClass::PushLuaxMemberRef(LuaxState& state, int refID) + { + if (PushLuaxRefTable(state)) + { + lua_rawgeti(state, -1, refID); + lua_replace(state, -2); // ref table + if (lua_isnil(state, -1)) + goto failed; + return true; + } + lua_pushnil(state); + failed: + return false; + } + + template + void LuaxNativeClass::ClearLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef) + { + if (memRef) + { + if (PushLuaxRefTable(state)) + { + luaL_unref(state, -1, memRef.refID); + state.Pop(); // ref table + } + memRef.refID = LUA_NOREF; + } + } + + //--------------------------------------------------------------------------------// + + /// + /// 释放工厂创建的实例 + /// + template + int LuaxNativeClass::__gc(lua_State* L) + { + LUAX_STATE(L); + + TYPE* self = state.GetUserdata(1); + assert(self); + +#if LUAX_PROFILER + std::cout << "Luax: GC<" << TYPE::GetLuaxClassName() << ">\n"; +#endif + + if(self->mWatchDog.mVMRef > 0) + --self->mWatchDog.mVMRef; + + self->Release(); + + return 0; + } + + /// + /// 输出格式如下: + /// 地址 类名 + /// + template + int LuaxNativeClass::__tostring(lua_State* L) + { + // params: + // 1: userdata + + LUAX_STATE(L); + TYPE* self = state.GetUserdata(1); + if (self) + { + cc8* classname = ""; + lua_getfield(state, 1, "GetClassName"); + if (state.IsType(-1, LUA_TFUNCTION)) + { + lua_pushvalue(L, 1); // userdata + state.Call(1, 1); // 派生类的GetClassName函数 + classname = state.GetValue(-1, ""); + } + else + { + classname = TYPE::GetLuaxClassName(); + } + lua_pushfstring(L, "%s: %p", classname, self); + return 1; + } + return 0; + } + +#if LUAX_ENABLE_NATIVE_EXTEND + /// + /// 派生出子类,在lua里对派生类的成员和行为进行重新设计,但是保证了userdata的统一。Native class的派生提供__init支持,在 + /// native实体创建后可以使用__init进行初始化,派生类拥有和基类一样的New参数列表,且native对象是一样的类型。 + /// + template + int LuaxNativeClass::_ExtendFactory(lua_State* L) + { + // upvalues: + // 1: base class + + // params: + // 1: class name + + int baseClass = lua_upvalueindex(1); + + lua_newtable(L); // class table + + int inheritClass = lua_gettop(L); + + // .GetClassName() + cc8* type = lua_tostring(L, 1); + lua_pushstring(L, type); + lua_pushcclosure(L, luax_c_getupvalue, 1); + lua_setfield(L, -2, "GetClassName"); + + // .GetClass() + lua_pushvalue(L, inheritClass); + lua_pushcclosure(L, luax_c_getupvalue, 1); + lua_setfield(L, -2, "GetClass"); + + // .Extend() + lua_pushvalue(L, inheritClass); + lua_pushcclosure(L, _ExtendFactory, 1); + lua_setfield(L, -2, "Extend"); + + // .New() + lua_pushvalue(L, inheritClass); + lua_getfield(L, baseClass, "New"); + lua_pushcclosure(L, _New, 2); + lua_setfield(L, -2, "New"); + + // __base = baseClass + lua_pushvalue(L, baseClass); + lua_setfield(L, -2, "__base"); + + // __index = inheritClass + lua_pushvalue(L, inheritClass); + lua_setfield(L, -2, "__index"); + + // metatable is baseClass + lua_pushvalue(L, baseClass); + lua_setmetatable(L, inheritClass); + + return 1; + } + + template + int LuaxNativeClass::_ExtendSingleton(lua_State* L) + { + // upvalues: + // 1: base class + + // params: + // 1: class name + + int baseClass = lua_upvalueindex(1); + + lua_newtable(L); // class name + + int inheritClass = lua_gettop(L); + + // .GetClassName() + cc8* type = lua_tostring(L, 1); + lua_pushstring(L, type); + lua_pushcclosure(L, luax_c_getupvalue, 1); + lua_setfield(L, -2, "GetClassName"); + + // .GetClass() + lua_pushvalue(L, inheritClass); + lua_pushcclosure(L, luax_c_getupvalue, 1); + lua_setfield(L, -2, "GetClass"); + + // .Extend() + lua_pushvalue(L, inheritClass); + lua_pushcclosure(L, _ExtendFactory, 1); + lua_setfield(L, -2, "Extend"); + + // __base = baseClass + lua_pushvalue(L, baseClass); + lua_setfield(L, -2, "__base"); + + // __index = inheritClass + lua_pushvalue(L, inheritClass); + lua_setfield(L, -2, "__index"); + + // metatable is baseClass + lua_pushvalue(L, baseClass); + lua_setmetatable(L, inheritClass); + + return 1; + } +#endif /*LUAX_ENABLE_NATIVE_EXTEND*/ + + template + int LuaxNativeClass::_GetClass(lua_State* L) + { + LUAX_STATE(L); + if (!mClassTable) + lua_pushnil(L); + else + mClassTable.PushRef(state); + return 1; + } + + template + int LuaxNativeClass::_GetRefTable(lua_State* L) + { + LUAX_STATE(L); + TYPE* self = state.GetUserdata(1); + bool success = self->PushLuaxRefTable(state); + if (!success) + lua_pushnil(L); + return 1; + } + + template + int LuaxNativeClass::_New(lua_State* L) + { + LUAX_STATE(L); + + // upvalues: + // 1: class table + // 2: original New() + + // stack: + // -1~-n: args + + int n = lua_gettop(L); // n args + + lua_pushvalue(L, lua_upvalueindex(2)); + if (state.IsType(-1, LUA_TFUNCTION)) + { + // stack: + // -1: New + // -2~-1-n: args + + state.PushValues(-1 - n, n); + + // stack: + // -1~-n: args + // -n-1: New + // -n-2~-1-2n: args + + state.Call(n, 1); + + // stack: + // -1: userdata + // -2~-1-n: args + + // reset member table's metatable to class table + if (state.IsType(-1, LUA_TUSERDATA)) + { + if (lua_getmetatable(L, -1)) // ref table + { + if (lua_getmetatable(L, -1)) // member table + { + lua_pushvalue(L, lua_upvalueindex(1)); // class table + lua_setmetatable(L, -2); + state.Pop(); // member table + } + state.Pop(); // ref table + } + + // stack: + // -1: userdata + // -2~-1-n: args + + int args = state.AbsIndex(-1 - n); + + // 尝试调用__init函数 + lua_getfield(L, lua_upvalueindex(1), "__init"); + + if (state.IsType(-1, LUA_TFUNCTION)) + { + lua_pushvalue(L, -2); // userdata + state.PushValues(args, n); + state.Call(n + 1, 0); + } + else + state.Pop(); + + } + + return 1; + } + return 0; + } + + template LuaxStrongRef LuaxNativeClass::mClassTable; // class table + template LuaxStrongRef LuaxNativeClass::mSingletonRefTable; // 单例 + +} \ No newline at end of file diff --git a/source/external/Luax/luax_class.inl b/source/external/Luax/luax_class.inl deleted file mode 100644 index 1d6a89f..0000000 --- a/source/external/Luax/luax_class.inl +++ /dev/null @@ -1,637 +0,0 @@ -namespace Luax -{ - - //--------------------------------------------------------------------------------// - - /// - /// 对不同类型,通过调用GetLuaClassName获得类型名,如果是派生类,GetClassName会被覆盖,指向luax_c_getupvalue。 - /// - template - int LuaxNativeClass::_GetClassName(lua_State* L) - { - LUAX_SETUP(L, "*"); - - cc8* type = TYPE::GetLuaxClassName(); - state.Push(type); - return 1; - } - - //--------------------------------------------------------------------------------// - - /// - /// 注册工厂和单例共有的类成员 - /// - template - void LuaxNativeClass::RegisterLuaxClassShared(LuaxState& state) - { - luaL_Reg regTable[] = { - { "GetClass", _GetClass }, - { "GetClassName", _GetClassName }, - { NULL, NULL } - }; - - state.RegisterMethods(regTable); - } - - /// - /// 工厂类的成员,注册在class table - /// - template - void LuaxNativeClass::RegisterLuaxFactoryClass(LuaxState& state) - { - luaL_Reg regTable[] = { - { "GetRefTable", _GetRefTable }, - { NULL, NULL } - }; - - state.RegisterMethods(regTable); - } - - /// - /// 单例类的成员,注册在class table - /// - template - void LuaxNativeClass::RegisterLuaxSingletonClass(LuaxState& state) - { - luaL_Reg regTable[] = { - { NULL, NULL } - }; - - state.RegisterMethods(regTable); - } - - template - void LuaxNativeClass::PushLuaxClassTable(LuaxState& state) - { - assert(mClassTable); - - mClassTable.PushRef(state); - } - - template - void LuaxNativeClass::SetLuaxClassTableRef(LuaxState& state, int idx) - { - mClassTable.SetRef(state, idx); - } - - template - LuaxNativeClass::LuaxNativeClass() - : mWatchDog() -#if LUAX_PROFILER - , mSafer(false) -#endif - { - } - - template - LuaxNativeClass::~LuaxNativeClass() - { - } - -#if LUAX_PROFILER - template - void LuaxNativeClass::operator delete(void* pdead, size_t size) - { - if (pdead == nullptr) - return; - // 堆上创建的实例必须使用Release释放。 - TYPE* p = static_cast(pdead); - assert(p->mSafer); - ::operator delete(pdead, size); - } -#endif - - template - void LuaxNativeClass::Retain() - { - ++mWatchDog.mNativeRef; - } - - template - void LuaxNativeClass::Release() - { - if (mWatchDog.mNativeRef > 0) - --mWatchDog.mNativeRef; - if (mWatchDog) - { -#if LUAX_PROFILER - mSafer = true; -#endif - delete this; - } - } - - template - template - void LuaxNativeClass::LuaxRetain(LuaxState& state, U* userdata) - { - if (PushLuaxRefTable(state)) - { - if (userdata->PushLuaxUserdata(state)) - { - lua_pushvalue(state, -1); // copy the userdata - lua_gettable(state, -3); // get the count (or nil) - u32 count = state.GetValue(-1, 0); // get the count (or 0) - lua_pop(state, 1); // pop the old count - lua_pushnumber(state, count + 1); // push the new count - lua_settable(state, -3); // save it in the table: reftable[userdata] = count - } - } - } - - template - template - void LuaxNativeClass::LuaxRelease(LuaxState& state, U* userdata) - { - if (PushLuaxRefTable(state)) - { - if (userdata->PushLuaxUserdata(state)) - { - lua_pushvalue(state, -1); // copy the userdata - lua_gettable(state, -3); // get the count (or nil) - u32 count = state.GetValue(-1, 0); // get the count (or 0) - lua_pop(state, 1); // pop the old count - - // no such reference - if (count == 0) - { - state.Pop(2); // userdata, reftable - return; // nothing to do - } - - if (count > 1) { - lua_pushnumber(state, count - 1); // push the new count - } - else { - lua_pushnil(state); // maybe cause gc - } - lua_settable(state, -3); // save it in the table - - state.Pop(1); // reftable - return; - } - state.Pop(2); // nil, reftable - return; - } - } - - template - bool LuaxNativeClass::PushLuaxUserdata(LuaxState& state) - { - assert(!TYPE::IsLuaxClassSingleton()); - if (!mUserdata) - { - BindToLua(state); - return true; - } - return mUserdata.PushRef(state); - } - - template - bool LuaxNativeClass::PushLuaxMemberTable(LuaxState& state) - { - int top = state.GetTop(); - if (this->PushLuaxUserdata(state)) - { - if (lua_getmetatable(state, -1)) // ref table - { - lua_replace(state, -2); - if (lua_getmetatable(state, -1)) // member table - { - lua_replace(state, -2); - return true; - } - } - } - lua_settop(state, top); - lua_pushnil(state); - return false; - } - - template - bool LuaxNativeClass::PushLuaxRefTable(LuaxState& state) - { - // Singleton - if (TYPE::IsLuaxClassSingleton()) - { - if (!this->mSingletonRefTable) { - lua_newtable(state); - this->mSingletonRefTable.SetRef(state, -1); // strong ref to member table won't be garbage collected - } - else { - this->mSingletonRefTable.PushRef(state); - } - return true; - } - // Factory - else - { - if (this->PushLuaxUserdata(state)) - { - if (lua_getmetatable(state, -1)) - { - lua_replace(state, -2); - return true; - } - } - } - return false; - } - - /// - /// 创建userdata,并以此添加ref table,member table和class table。 - /// ref table 是kv强引用table,保存对其他userdata的引用计数(通过userdata作为key, - /// 计数为value),以及成员引用 - /// member table 保存lua创建的实例的成员 - /// class table 所有本类型的实例共有的函数表 - /// - /// BindToLua只会在第一次注册给Lua虚拟机时调用。 - /// - template - void LuaxNativeClass::BindToLua(LuaxState& state) - { - // 单例不能绑定userdata - assert(!TYPE::IsLuaxClassSingleton()); - assert(!mUserdata); - - /// - /// 创建userdata并留在栈顶,注意地址要转换为TYPE*,直接用this可能会导致多重继承的类丧失多态。 - /// 如果直接传this进去,在多重继承情况下,是拿不到另一头的虚函数表的。所以这里需要将this - /// 转换为整个对象的低地址,这样可以拿到另一个基类的虚函数表,通过另一个基类实现多态。 - /// - TYPE* p = static_cast(this); - state.PushPtrUserdata(p); - - lua_newtable(state); // ref table,无法在lua处访问,用来管理C对象的生命周期 - lua_newtable(state); // member table,lua中创建的对象成员都保存在这里 - PushLuaxClassTable(state); // class table - - // stack: - // -1: class table - // -2: member table - // -3: ref table - // -4: userdata - - int top = state.GetTop(); - int memberTable = top - 1; - int refTable = top - 2; - - // ref table 注册 __tostring 和 __gc - lua_pushcfunction(state, __tostring); - lua_setfield(state, refTable, "__tostring"); - - lua_pushcfunction(state, __gc); - lua_setfield(state, refTable, "__gc"); - - // ref table 的 __index 和 __newindex 设为 member table - lua_pushvalue(state, memberTable); - lua_setfield(state, refTable, "__index"); - - lua_pushvalue(state, memberTable); - lua_setfield(state, refTable, "__newindex"); - - // 设置元表 - lua_setmetatable(state, -2); // class is meta of member - lua_setmetatable(state, -2); // member is meta of ref - lua_setmetatable(state, -2); // ref is meta of userdata - - // 设置一个userdata的弱引用,方便通过PushLuaUserdata方法返回lua对象 - mUserdata.SetRef(state, -1); - assert(mUserdata); - - // 增加一个虚拟机引用,在GC时-1 - ++mWatchDog.mVMRef; -#if LUAX_PROFILER - mRefVMs.insert(state.GetVM()); -#endif - } - - /// - /// 成员引用管理 - /// - template - void LuaxNativeClass::SetLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef, int idx) - { - ClearLuaxMemberRef(state, memRef); - if (!lua_isnil(state, idx)) - { - idx = state.AbsIndex(idx); - if (PushLuaxRefTable(state)) - { - lua_pushvalue(state, idx); - memRef.refID = luaL_ref(state, -2); - state.Pop(); // ref table - } - } - } - - template - bool LuaxNativeClass::PushLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef) - { - if (memRef) - { - if (PushLuaxRefTable(state)) - { - lua_rawgeti(state, -1, memRef.refID); - lua_replace(state, -2); // ref table - if (lua_isnil(state, -1)) - goto failed; - return true; - } - } - lua_pushnil(state); - failed: - memRef.refID = LUA_NOREF; - return false; - } - - template - bool LuaxNativeClass::PushLuaxMemberRef(LuaxState& state, int refID) - { - if (PushLuaxRefTable(state)) - { - lua_rawgeti(state, -1, refID); - lua_replace(state, -2); // ref table - if (lua_isnil(state, -1)) - goto failed; - return true; - } - lua_pushnil(state); - failed: - return false; - } - - template - void LuaxNativeClass::ClearLuaxMemberRef(LuaxState& state, LuaxMemberRef& memRef) - { - if (memRef) - { - if (PushLuaxRefTable(state)) - { - luaL_unref(state, -1, memRef.refID); - state.Pop(); // ref table - } - memRef.refID = LUA_NOREF; - } - } - - //--------------------------------------------------------------------------------// - - /// - /// 释放工厂创建的实例 - /// - template - int LuaxNativeClass::__gc(lua_State* L) - { - LUAX_STATE(L); - - TYPE* self = state.GetUserdata(1); - assert(self); - -#if LUAX_PROFILER - std::cout << "Luax: GC<" << TYPE::GetLuaxClassName() << ">\n"; -#endif - - if(self->mWatchDog.mVMRef > 0) - --self->mWatchDog.mVMRef; - - self->Release(); - - return 0; - } - - /// - /// 输出格式如下: - /// 地址 类名 - /// - template - int LuaxNativeClass::__tostring(lua_State* L) - { - // params: - // 1: userdata - - LUAX_STATE(L); - TYPE* self = state.GetUserdata(1); - if (self) - { - cc8* classname = ""; - lua_getfield(state, 1, "GetClassName"); - if (state.IsType(-1, LUA_TFUNCTION)) - { - lua_pushvalue(L, 1); // userdata - state.Call(1, 1); // 派生类的GetClassName函数 - classname = state.GetValue(-1, ""); - } - else - { - classname = TYPE::GetLuaxClassName(); - } - lua_pushfstring(L, "%s: %p", classname, self); - return 1; - } - return 0; - } - -#if LUAX_ENABLE_NATIVE_EXTEND - /// - /// 派生出子类,在lua里对派生类的成员和行为进行重新设计,但是保证了userdata的统一。Native class的派生提供__init支持,在 - /// native实体创建后可以使用__init进行初始化,派生类拥有和基类一样的New参数列表,且native对象是一样的类型。 - /// - template - int LuaxNativeClass::_ExtendFactory(lua_State* L) - { - // upvalues: - // 1: base class - - // params: - // 1: class name - - int baseClass = lua_upvalueindex(1); - - lua_newtable(L); // class table - - int inheritClass = lua_gettop(L); - - // .GetClassName() - cc8* type = lua_tostring(L, 1); - lua_pushstring(L, type); - lua_pushcclosure(L, luax_c_getupvalue, 1); - lua_setfield(L, -2, "GetClassName"); - - // .GetClass() - lua_pushvalue(L, inheritClass); - lua_pushcclosure(L, luax_c_getupvalue, 1); - lua_setfield(L, -2, "GetClass"); - - // .Extend() - lua_pushvalue(L, inheritClass); - lua_pushcclosure(L, _ExtendFactory, 1); - lua_setfield(L, -2, "Extend"); - - // .New() - lua_pushvalue(L, inheritClass); - lua_getfield(L, baseClass, "New"); - lua_pushcclosure(L, _New, 2); - lua_setfield(L, -2, "New"); - - // __base = baseClass - lua_pushvalue(L, baseClass); - lua_setfield(L, -2, "__base"); - - // __index = inheritClass - lua_pushvalue(L, inheritClass); - lua_setfield(L, -2, "__index"); - - // metatable is baseClass - lua_pushvalue(L, baseClass); - lua_setmetatable(L, inheritClass); - - return 1; - } - - template - int LuaxNativeClass::_ExtendSingleton(lua_State* L) - { - // upvalues: - // 1: base class - - // params: - // 1: class name - - int baseClass = lua_upvalueindex(1); - - lua_newtable(L); // class name - - int inheritClass = lua_gettop(L); - - // .GetClassName() - cc8* type = lua_tostring(L, 1); - lua_pushstring(L, type); - lua_pushcclosure(L, luax_c_getupvalue, 1); - lua_setfield(L, -2, "GetClassName"); - - // .GetClass() - lua_pushvalue(L, inheritClass); - lua_pushcclosure(L, luax_c_getupvalue, 1); - lua_setfield(L, -2, "GetClass"); - - // .Extend() - lua_pushvalue(L, inheritClass); - lua_pushcclosure(L, _ExtendFactory, 1); - lua_setfield(L, -2, "Extend"); - - // __base = baseClass - lua_pushvalue(L, baseClass); - lua_setfield(L, -2, "__base"); - - // __index = inheritClass - lua_pushvalue(L, inheritClass); - lua_setfield(L, -2, "__index"); - - // metatable is baseClass - lua_pushvalue(L, baseClass); - lua_setmetatable(L, inheritClass); - - return 1; - } -#endif /*LUAX_ENABLE_NATIVE_EXTEND*/ - - template - int LuaxNativeClass::_GetClass(lua_State* L) - { - LUAX_STATE(L); - if (!mClassTable) - lua_pushnil(L); - else - mClassTable.PushRef(state); - return 1; - } - - template - int LuaxNativeClass::_GetRefTable(lua_State* L) - { - LUAX_STATE(L); - TYPE* self = state.GetUserdata(1); - bool success = self->PushLuaxRefTable(state); - if (!success) - lua_pushnil(L); - return 1; - } - - template - int LuaxNativeClass::_New(lua_State* L) - { - LUAX_STATE(L); - - // upvalues: - // 1: class table - // 2: original New() - - // stack: - // -1~-n: args - - int n = lua_gettop(L); // n args - - lua_pushvalue(L, lua_upvalueindex(2)); - if (state.IsType(-1, LUA_TFUNCTION)) - { - // stack: - // -1: New - // -2~-1-n: args - - state.PushValues(-1 - n, n); - - // stack: - // -1~-n: args - // -n-1: New - // -n-2~-1-2n: args - - state.Call(n, 1); - - // stack: - // -1: userdata - // -2~-1-n: args - - // reset member table's metatable to class table - if (state.IsType(-1, LUA_TUSERDATA)) - { - if (lua_getmetatable(L, -1)) // ref table - { - if (lua_getmetatable(L, -1)) // member table - { - lua_pushvalue(L, lua_upvalueindex(1)); // class table - lua_setmetatable(L, -2); - state.Pop(); // member table - } - state.Pop(); // ref table - } - - // stack: - // -1: userdata - // -2~-1-n: args - - int args = state.AbsIndex(-1 - n); - - // 尝试调用__init函数 - lua_getfield(L, lua_upvalueindex(1), "__init"); - - if (state.IsType(-1, LUA_TFUNCTION)) - { - lua_pushvalue(L, -2); // userdata - state.PushValues(args, n); - state.Call(n + 1, 0); - } - else - state.Pop(); - - } - - return 1; - } - return 0; - } - - template LuaxStrongRef LuaxNativeClass::mClassTable; // class table - template LuaxStrongRef LuaxNativeClass::mSingletonRefTable; // 单例 - -} \ No newline at end of file diff --git a/source/external/Luax/luax_state.inc b/source/external/Luax/luax_state.inc new file mode 100644 index 0000000..6671bb5 --- /dev/null +++ b/source/external/Luax/luax_state.inc @@ -0,0 +1,180 @@ +namespace Luax +{ + + /// + /// 注册工厂,注册class table,以type name为键设置在名称空间上。在注册阶段不会设置元表,等到New方法调用的时候才会。 + /// + template + void LuaxState::RegisterFactory() + { + cc8* type = TYPE::GetLuaxFactoryName(); + + lua_State* L = mState; + LuaxState& state = *this; + + int top = lua_gettop(L); // namespace table + assert(lua_istable(L, top)); + + // class table + lua_newtable(L); + TYPE::RegisterLuaxClassShared(state); + TYPE::RegisterLuaxFactoryClass(state); + TYPE::RegisterLuaxClass(state); + + // 检测TYPE里面是否没有注册必须的方法 +#define _assertmethod(I, NAME) \ + GetField(I, NAME); \ + assert(IsType(-1, LUA_TFUNCTION)); \ + Pop(); + + //_assertmethod(-1, "New"); + +#undef _assertmethod + +#if LUAX_ENABLE_NATIVE_EXTEND + // .Extend() + lua_pushvalue(state, -1); // class table + lua_pushcclosure(state, TYPE::_ExtendFactory, 1); + lua_setfield(state, -2, "Extend"); +#endif + + // class["__index"] = class + lua_pushvalue(state, -1); // class table + lua_setfield(state, -2, "__index"); + + TYPE::SetLuaxClassTableRef(state, -1); + + SetField(top, type); + + // reset top + lua_settop(L, top); + + // 后处理 + TYPE::RegisterLuaxPostprocess(state); + } + + /// + /// Singleton + /// + template + void LuaxState::RegisterSingleton() + { + lua_State* L = mState; + LuaxState& state = *this; + + int top = lua_gettop(L); // namespace table + assert(lua_istable(L, top)); + + // class table. + lua_newtable(L); + TYPE::RegisterLuaxClassShared(state); + TYPE::RegisterLuaxSingletonClass(state); + TYPE::RegisterLuaxClass(state); + + TYPE::SetLuaxClassTableRef(state, -1); + + lua_pushvalue(state, -1); + lua_setfield(state, -2, "__index"); + +#if LUAX_ENABLE_NATIVE_EXTEND + // .Extend() + lua_pushvalue(state, -1); // class table + lua_pushcclosure(state, TYPE::_ExtendSingleton, 1); + lua_setfield(state, -2, "Extend"); +#endif + + cc8* type = TYPE::GetLuaxSingletonName(); + SetField(top, type); + + // reset top + lua_settop(L, top); + + // 后处理 + TYPE::RegisterLuaxPostprocess(state); + } + + template + void LuaxState::SetField(int idx, cc8* key, TYPE value) + { + if (IsTableOrUserdata(idx)) + { + idx = AbsIndex(idx); + this->Push(value); + lua_setfield(mState, idx, key); + } + } + + template + void LuaxState::SetFieldByIndex(int idx, int key, TYPE value) + { + if (IsTableOrUserdata(idx)) + { + idx = AbsIndex(idx); + this->Push(value); + lua_rawseti(mState, idx, key); + } + } + + template + TYPE LuaxState::GetField(int idx, cc8* key, TYPE value) + { + GetField(idx, key); + TYPE result = GetValue < TYPE >(-1, value); + this->Pop(); + + return result; + } + + template + TYPE LuaxState::GetField(int idx, int key, TYPE value) + { + GetField(idx, key); + TYPE result = GetValue < TYPE >(-1, value); + Pop(); + + return result; + } + + template + TYPE* LuaxState::GetUserdata(int idx) + { + void* p = nullptr; + + if (IsType(idx, LUA_TUSERDATA)) + { + p = *(void**)lua_touserdata(mState, idx); + } + + return static_cast(p); + } + + template + TYPE* LuaxState::CheckUserdata(int idx) + { + if (IsType(idx, LUA_TUSERDATA)) + { + if (lua_getmetatable(mState, idx)) // ref table + { + if (lua_getmetatable(mState, -1)) // member table + { + if (lua_getmetatable(mState, -1)) // class table + { + TYPE::PushLuaxClassTable(*this); // target class table + if (lua_rawequal(mState, -1, -2)) + { + Pop(4); // ref\member\class\target class + TYPE* udata = GetUserdata(idx); + return udata; // userdata + } + Pop(2); // target class table\class table + } + Pop(1); // member table + } + Pop(1); // ref table + } + } + luaL_typerror(mState, idx, TYPE::GetLuaxClassName()); + return nullptr; + } + +} \ No newline at end of file diff --git a/source/external/Luax/luax_state.inl b/source/external/Luax/luax_state.inl deleted file mode 100644 index 6671bb5..0000000 --- a/source/external/Luax/luax_state.inl +++ /dev/null @@ -1,180 +0,0 @@ -namespace Luax -{ - - /// - /// 注册工厂,注册class table,以type name为键设置在名称空间上。在注册阶段不会设置元表,等到New方法调用的时候才会。 - /// - template - void LuaxState::RegisterFactory() - { - cc8* type = TYPE::GetLuaxFactoryName(); - - lua_State* L = mState; - LuaxState& state = *this; - - int top = lua_gettop(L); // namespace table - assert(lua_istable(L, top)); - - // class table - lua_newtable(L); - TYPE::RegisterLuaxClassShared(state); - TYPE::RegisterLuaxFactoryClass(state); - TYPE::RegisterLuaxClass(state); - - // 检测TYPE里面是否没有注册必须的方法 -#define _assertmethod(I, NAME) \ - GetField(I, NAME); \ - assert(IsType(-1, LUA_TFUNCTION)); \ - Pop(); - - //_assertmethod(-1, "New"); - -#undef _assertmethod - -#if LUAX_ENABLE_NATIVE_EXTEND - // .Extend() - lua_pushvalue(state, -1); // class table - lua_pushcclosure(state, TYPE::_ExtendFactory, 1); - lua_setfield(state, -2, "Extend"); -#endif - - // class["__index"] = class - lua_pushvalue(state, -1); // class table - lua_setfield(state, -2, "__index"); - - TYPE::SetLuaxClassTableRef(state, -1); - - SetField(top, type); - - // reset top - lua_settop(L, top); - - // 后处理 - TYPE::RegisterLuaxPostprocess(state); - } - - /// - /// Singleton - /// - template - void LuaxState::RegisterSingleton() - { - lua_State* L = mState; - LuaxState& state = *this; - - int top = lua_gettop(L); // namespace table - assert(lua_istable(L, top)); - - // class table. - lua_newtable(L); - TYPE::RegisterLuaxClassShared(state); - TYPE::RegisterLuaxSingletonClass(state); - TYPE::RegisterLuaxClass(state); - - TYPE::SetLuaxClassTableRef(state, -1); - - lua_pushvalue(state, -1); - lua_setfield(state, -2, "__index"); - -#if LUAX_ENABLE_NATIVE_EXTEND - // .Extend() - lua_pushvalue(state, -1); // class table - lua_pushcclosure(state, TYPE::_ExtendSingleton, 1); - lua_setfield(state, -2, "Extend"); -#endif - - cc8* type = TYPE::GetLuaxSingletonName(); - SetField(top, type); - - // reset top - lua_settop(L, top); - - // 后处理 - TYPE::RegisterLuaxPostprocess(state); - } - - template - void LuaxState::SetField(int idx, cc8* key, TYPE value) - { - if (IsTableOrUserdata(idx)) - { - idx = AbsIndex(idx); - this->Push(value); - lua_setfield(mState, idx, key); - } - } - - template - void LuaxState::SetFieldByIndex(int idx, int key, TYPE value) - { - if (IsTableOrUserdata(idx)) - { - idx = AbsIndex(idx); - this->Push(value); - lua_rawseti(mState, idx, key); - } - } - - template - TYPE LuaxState::GetField(int idx, cc8* key, TYPE value) - { - GetField(idx, key); - TYPE result = GetValue < TYPE >(-1, value); - this->Pop(); - - return result; - } - - template - TYPE LuaxState::GetField(int idx, int key, TYPE value) - { - GetField(idx, key); - TYPE result = GetValue < TYPE >(-1, value); - Pop(); - - return result; - } - - template - TYPE* LuaxState::GetUserdata(int idx) - { - void* p = nullptr; - - if (IsType(idx, LUA_TUSERDATA)) - { - p = *(void**)lua_touserdata(mState, idx); - } - - return static_cast(p); - } - - template - TYPE* LuaxState::CheckUserdata(int idx) - { - if (IsType(idx, LUA_TUSERDATA)) - { - if (lua_getmetatable(mState, idx)) // ref table - { - if (lua_getmetatable(mState, -1)) // member table - { - if (lua_getmetatable(mState, -1)) // class table - { - TYPE::PushLuaxClassTable(*this); // target class table - if (lua_rawequal(mState, -1, -2)) - { - Pop(4); // ref\member\class\target class - TYPE* udata = GetUserdata(idx); - return udata; // userdata - } - Pop(2); // target class table\class table - } - Pop(1); // member table - } - Pop(1); // ref table - } - } - luaL_typerror(mState, idx, TYPE::GetLuaxClassName()); - return nullptr; - } - -} \ No newline at end of file diff --git a/source/modules/asura-base/Config.h b/source/modules/asura-base/Config.h new file mode 100644 index 0000000..024ac79 --- /dev/null +++ b/source/modules/asura-base/Config.h @@ -0,0 +1,69 @@ +#ifndef __ASURA_BASE_CONFIG_H__ +#define __ASURA_BASE_CONFIG_H__ + +// 在编辑器下会编译的代码 +#define ASURA_EDITOR 1 + +// 在运行时中的代码 +#define ASURA_RUNTIME 1 + +//--------------------------------------------------------------------------------// + +#ifndef ASSERT +#ifdef NDEBUG +#define ASSERT(x) { false ? (void)(x) : (void)0; } +#else +#ifdef _WIN32 +#define ASURA_DEBUG_BREAK() __debugbreak() +#else +#define ASURA_DEBUG_BREAK() raise(SIGTRAP) +#endif +#define ASSERT(x) do { const volatile bool asura_assert_b____ = !(x); if(asura_assert_b____) ASURA_DEBUG_BREAK(); } while (false) +#endif +#endif + +//--------------------------------------------------------------------------------// + +#ifdef _WIN32 + #define ASURA_FINAL final + #define ASURA_EXPORT __declspec(dllexport) + #define ASURA_IMPORT __declspec(dllimport) + #define ASURA_FORCE_INLINE __forceinline + #define ASURA_RESTRICT __restrict + #define ASURA_API ASURA_EXPORT + #define ASURA_ATTRIBUTE_USED + #define ASURA_ABSTRACT + #define ASURA_WINDOWS 1 +#else + #define ASURA_FINAL final + #define ASURA_EXPORT __attribute__((visibility("default"))) + #define ASURA_IMPORT + #define ASURA_FORCE_INLINE __attribute__((always_inline)) inline + #define ASURA_RESTRICT __restrict__ + #define ASURA_ATTRIBUTE_USED __attribute__((used)) + #define ASURA_ABSTRACT + #define ASURA_API ASURA_EXPORT +#endif + +/// +/// 表明移动指针所有权 +/// +#define ASURA_MOVE + +#define ASURA_DEBUG 0 + +//--------------------------------------------------------------------------------// + +#define ASURA_SDL_HOST 1 + +#define ASURA_LITTLE_ENDIAN 1 + +//--------------------------------------------------------------------------------// +// 扩展关键字 + +#define ASURA_THROW(ex) throw(ex) // 暗示抛出异常 + +#define ASURA_OUT +#define ASURA_REF + +#endif \ No newline at end of file diff --git a/source/modules/asura-box2d/Box2DModule.cpp b/source/modules/asura-box2d/Box2DModule.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Box2DModule.h b/source/modules/asura-box2d/Box2DModule.h new file mode 100644 index 0000000..1a00608 --- /dev/null +++ b/source/modules/asura-box2d/Box2DModule.h @@ -0,0 +1,19 @@ +#ifndef __ASURA_BOX2D_MODULE_H__ +#define __ASURA_BOX2D_MODULE_H__ + +#include + +namespace AsuraEngine +{ + + class Box2DModule ASURA_FINAL : public Module + { + public: + + + + }; + +} + +#endif \ No newline at end of file diff --git a/source/modules/asura-box2d/Physics/Body.h b/source/modules/asura-box2d/Physics/Body.h new file mode 100644 index 0000000..e5af76a --- /dev/null +++ b/source/modules/asura-box2d/Physics/Body.h @@ -0,0 +1,67 @@ +#ifndef __ASURA_BOX2D_BODY_H__ +#define __ASURA_BOX2D_BODY_H__ + +#include + +#include + +namespace AsuraEngine +{ + namespace Physics + { + + class World; + class Joint; + + enum BodyType + { + BODY_TYPE_INVALID, + BODY_TYPE_STATIC, + BODY_TYPE_DYNAMIC, + BODY_TYPE_KINEMATIC + }; + + class Body + : public AEScripting::Portable + { + public: + + private: + + friend class Joint; + + //----------------------------------------------------------------------------// + + LUAX_DECL_FACTORY(Body); + + LUAX_DECL_ENUM(BodyType, 1); + + LUAX_DECL_METHOD(_GetType); + LUAX_DECL_METHOD(_GetX); + LUAX_DECL_METHOD(_GetY); + LUAX_DECL_METHOD(_GetAngle); + LUAX_DECL_METHOD(_GetPosition); + LUAX_DECL_METHOD(_GetLinearVelocity); + LUAX_DECL_METHOD(_GetWorldCenter); + LUAX_DECL_METHOD(_GetLocalCenter); + LUAX_DECL_METHOD(_GetAngularVelocity); + LUAX_DECL_METHOD(_GetMass); + LUAX_DECL_METHOD(_GetInertia); + LUAX_DECL_METHOD(_GetMassData); + LUAX_DECL_METHOD(_GetAngularDamping); + LUAX_DECL_METHOD(_GetLinearDamping); + LUAX_DECL_METHOD(_GetGravityScale); + LUAX_DECL_METHOD(_GetGravityScale); + + //----------------------------------------------------------------------------// + + b2Body *body; + + World* mWorld; + + }; + + } +} + +#endif \ No newline at end of file diff --git a/source/modules/asura-box2d/Physics/ChainShape.h b/source/modules/asura-box2d/Physics/ChainShape.h new file mode 100644 index 0000000..2ce19fb --- /dev/null +++ b/source/modules/asura-box2d/Physics/ChainShape.h @@ -0,0 +1,29 @@ +#ifndef __ASURA_CHAIN_SHAPE_H__ +#define __ASURA_CHAIN_SHAPE_H__ + +#include + +#include +#include + +namespace_begin(AsuraEngine) +namespace_begin(Physics) + +class ChainShape + : AEScripting::Portable +{ +public: + + ChainShape(); + ~ChainShape(); + +private: + + b2ChainShape* mShape; + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-box2d/Physics/CircleShape.h b/source/modules/asura-box2d/Physics/CircleShape.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/Contact.h b/source/modules/asura-box2d/Physics/Contact.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/DebugDraw.h b/source/modules/asura-box2d/Physics/DebugDraw.h new file mode 100644 index 0000000..a92be43 --- /dev/null +++ b/source/modules/asura-box2d/Physics/DebugDraw.h @@ -0,0 +1,9 @@ +#ifndef _ASURA_BOX2D_DEBUG_DRAW_H_ +#define _ASURA_BOX2D_DEBUG_DRAW_H_ + +namespace AsuraEngine +{ + +} + +#endif \ No newline at end of file diff --git a/source/modules/asura-box2d/Physics/DistanceJoint.h b/source/modules/asura-box2d/Physics/DistanceJoint.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/EdgeShape.h b/source/modules/asura-box2d/Physics/EdgeShape.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/Fixture.h b/source/modules/asura-box2d/Physics/Fixture.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/FrictionJoint.h b/source/modules/asura-box2d/Physics/FrictionJoint.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/GearJoint.h b/source/modules/asura-box2d/Physics/GearJoint.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/Joint.h b/source/modules/asura-box2d/Physics/Joint.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/MotorJoint.h b/source/modules/asura-box2d/Physics/MotorJoint.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/MouseJoint.h b/source/modules/asura-box2d/Physics/MouseJoint.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/PolygonShape.h b/source/modules/asura-box2d/Physics/PolygonShape.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/PrismaticJoint.h b/source/modules/asura-box2d/Physics/PrismaticJoint.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/PulleyJoint.h b/source/modules/asura-box2d/Physics/PulleyJoint.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/RevoluteJoint.h b/source/modules/asura-box2d/Physics/RevoluteJoint.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/RopeJoint.h b/source/modules/asura-box2d/Physics/RopeJoint.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/Shape.h b/source/modules/asura-box2d/Physics/Shape.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/WeldJoint.h b/source/modules/asura-box2d/Physics/WeldJoint.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/WheelJoint.h b/source/modules/asura-box2d/Physics/WheelJoint.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-box2d/Physics/World.h b/source/modules/asura-box2d/Physics/World.h new file mode 100644 index 0000000..b6d00ca --- /dev/null +++ b/source/modules/asura-box2d/Physics/World.h @@ -0,0 +1,19 @@ +#ifndef __ASURA_BOX2D_WORLD_H__ +#define __ASURA_BOX2D_WORLD_H__ + +#include + +namespace AsuraEngine +{ + namespace Physics + { + + class World : public AEScripting::Portable + { + + }; + + } +} + +#endif \ No newline at end of file diff --git a/source/modules/asura-box2d/Physics/binding/_body.cpp b/source/modules/asura-box2d/Physics/binding/_body.cpp new file mode 100644 index 0000000..0c9e3e8 --- /dev/null +++ b/source/modules/asura-box2d/Physics/binding/_body.cpp @@ -0,0 +1,171 @@ +#include "../Body.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Physics + { + + LUAX_REGISTRY(Body) + { + LUAX_REGISTER_METHODS(state, + { "GetType", _GetType }, + { "GetX", _GetX }, + { "GetY", _GetY }, + { "GetAngle", _GetAngle }, + { "GetPosition", _GetPosition }, + { "GetLinearVelocity", _GetLinearVelocity }, + { "GetWorldCenter", _GetWorldCenter }, + { "GetLocalCenter", _GetLocalCenter }, + { "GetAngularVelocity", _GetAngularVelocity }, + { "GetMass", _GetMass }, + { "GetInertia", _GetInertia }, + { "GetMassData", _GetMassData }, + { "GetAngularDamping", _GetAngularDamping }, + { "GetLinearDamping", _GetLinearDamping }, + { "GetGravityScale", _GetGravityScale }, + { "GetGravityScale", _GetGravityScale } + ); + } + + LUAX_POSTPROCESS(Body) + { + LUAX_REGISTER_ENUM(state, "EBodyType", + { "INVALID", BODY_TYPE_INVALID }, + { "STATIC", BODY_TYPE_STATIC }, + { "DYNAMIC", BODY_TYPE_DYNAMIC }, + { "KINEMATIC", BODY_TYPE_KINEMATIC } + ); + + } + + // body:GetType() + LUAX_IMPL_METHOD(Body, _GetType) + { + LUAX_PREPARE(L, Body); + return 0; + } + + // body:GetX() + LUAX_IMPL_METHOD(Body, _GetX) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetY() + LUAX_IMPL_METHOD(Body, _GetY) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetAngle() + LUAX_IMPL_METHOD(Body, _GetAngle) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetPosition() + LUAX_IMPL_METHOD(Body, _GetPosition) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetLinearVelocity() + LUAX_IMPL_METHOD(Body, _GetLinearVelocity) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetWorldCenter() + LUAX_IMPL_METHOD(Body, _GetWorldCenter) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetLocalCenter() + LUAX_IMPL_METHOD(Body, _GetLocalCenter) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetAngularVelocity() + LUAX_IMPL_METHOD(Body, _GetAngularVelocity) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetMass() + LUAX_IMPL_METHOD(Body, _GetMass) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetInertia() + LUAX_IMPL_METHOD(Body, _GetInertia) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetMassData() + LUAX_IMPL_METHOD(Body, _GetMassData) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetAngularDamping() + LUAX_IMPL_METHOD(Body, _GetAngularDamping) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetLinearDamping() + LUAX_IMPL_METHOD(Body, _GetLinearDamping) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetGravityScale() + LUAX_IMPL_METHOD(Body, _GetGravityScale) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + // body:GetGravityScale() + LUAX_IMPL_METHOD(Body, _GetGravityScale) + { + LUAX_PREPARE(L, Body); + + return 0; + } + + } +} diff --git a/source/modules/asura-box2d/Physics/binding/_world.cpp b/source/modules/asura-box2d/Physics/binding/_world.cpp new file mode 100644 index 0000000..0940959 --- /dev/null +++ b/source/modules/asura-box2d/Physics/binding/_world.cpp @@ -0,0 +1,21 @@ +#include "../World.h" + +using namespace std; + +namespace AsuraEngine +{ + namespace Physics + { + /* + LUAX_REGISTRY(World) + { + + } + + LUAX_POSTPROCESS(World) + { + + } +*/ + } +} diff --git a/source/modules/asura-box2d/box2d_module.cpp b/source/modules/asura-box2d/box2d_module.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-box2d/box2d_module.h b/source/modules/asura-box2d/box2d_module.h deleted file mode 100644 index 052078a..0000000 --- a/source/modules/asura-box2d/box2d_module.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __ASURA_BOX2D_MODULE_H__ -#define __ASURA_BOX2D_MODULE_H__ - -#include - -namespace AsuraEngine -{ - - class Box2DModule ASURA_FINAL : public Module - { - public: - - - - }; - -} - -#endif \ No newline at end of file diff --git a/source/modules/asura-box2d/physics/binding/_body.cpp b/source/modules/asura-box2d/physics/binding/_body.cpp index 0dbd292..0c9e3e8 100644 --- a/source/modules/asura-box2d/physics/binding/_body.cpp +++ b/source/modules/asura-box2d/physics/binding/_body.cpp @@ -1,4 +1,4 @@ -#include "../body.h" +#include "../Body.h" using namespace std; diff --git a/source/modules/asura-box2d/physics/binding/_world.cpp b/source/modules/asura-box2d/physics/binding/_world.cpp index 1ebcbd1..0940959 100644 --- a/source/modules/asura-box2d/physics/binding/_world.cpp +++ b/source/modules/asura-box2d/physics/binding/_world.cpp @@ -1,4 +1,4 @@ -#include "../world.h" +#include "../World.h" using namespace std; diff --git a/source/modules/asura-box2d/physics/body.h b/source/modules/asura-box2d/physics/body.h index 3a4aa5f..e5af76a 100644 --- a/source/modules/asura-box2d/physics/body.h +++ b/source/modules/asura-box2d/physics/body.h @@ -3,7 +3,7 @@ #include -#include +#include namespace AsuraEngine { diff --git a/source/modules/asura-box2d/physics/chain_shape.h b/source/modules/asura-box2d/physics/chain_shape.h deleted file mode 100644 index dd03ddf..0000000 --- a/source/modules/asura-box2d/physics/chain_shape.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef __ASURA_CHAIN_SHAPE_H__ -#define __ASURA_CHAIN_SHAPE_H__ - -// 3rd-party -#include - -// asura modules -#include - -namespace AsuraEngine -{ - namespace Physics - { - - class ChainShape - : AEScripting::Portable - { - public: - - ChainShape(); - ~ChainShape(); - - private: - - b2ChainShape* mShape; - - }; - - } -} - -#endif \ No newline at end of file diff --git a/source/modules/asura-box2d/physics/circle_shape.h b/source/modules/asura-box2d/physics/circle_shape.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-box2d/physics/debug_draw.h b/source/modules/asura-box2d/physics/debug_draw.h deleted file mode 100644 index cff682b..0000000 --- a/source/modules/asura-box2d/physics/debug_draw.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef __ASURA_BOX2D_DEBUG_DRAW_H__ -#define __ASURA_BOX2D_DEBUG_DRAW_H__ - -namespace AsuraEngine -{ - -} - -#endif \ No newline at end of file diff --git a/source/modules/asura-box2d/physics/distance_joint.h b/source/modules/asura-box2d/physics/distance_joint.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-box2d/physics/edge_shape.h b/source/modules/asura-box2d/physics/edge_shape.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-box2d/physics/friction_joint.h b/source/modules/asura-box2d/physics/friction_joint.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-box2d/physics/gear_joint.h b/source/modules/asura-box2d/physics/gear_joint.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-box2d/physics/motor_joint.h b/source/modules/asura-box2d/physics/motor_joint.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-box2d/physics/mouse_joint.h b/source/modules/asura-box2d/physics/mouse_joint.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-box2d/physics/polygon_shape.h b/source/modules/asura-box2d/physics/polygon_shape.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-box2d/physics/prismatic_joint.h b/source/modules/asura-box2d/physics/prismatic_joint.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-box2d/physics/pulley_joint.h b/source/modules/asura-box2d/physics/pulley_joint.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-box2d/physics/revolute_joint.h b/source/modules/asura-box2d/physics/revolute_joint.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-box2d/physics/rope_joint.h b/source/modules/asura-box2d/physics/rope_joint.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-box2d/physics/weld_joint.h b/source/modules/asura-box2d/physics/weld_joint.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-box2d/physics/wheel_joint.h b/source/modules/asura-box2d/physics/wheel_joint.h deleted file mode 100644 index e69de29..0000000 diff --git a/source/modules/asura-box2d/physics/world.h b/source/modules/asura-box2d/physics/world.h index 0aac0c8..b6d00ca 100644 --- a/source/modules/asura-box2d/physics/world.h +++ b/source/modules/asura-box2d/physics/world.h @@ -1,7 +1,7 @@ #ifndef __ASURA_BOX2D_WORLD_H__ #define __ASURA_BOX2D_WORLD_H__ -#include +#include namespace AsuraEngine { diff --git a/source/modules/asura-core/Application.cpp b/source/modules/asura-core/Application.cpp new file mode 100644 index 0000000..2f20e45 --- /dev/null +++ b/source/modules/asura-core/Application.cpp @@ -0,0 +1,23 @@ +#include "Application.h" + +using namespace Luax; + +namespace AsuraEngine +{ + +Application::Application() +{ + +} + +Application::~Application() +{ + +} + +bool Application::InitSubModules(uint flag) +{ + return false; +} + +} \ No newline at end of file diff --git a/source/modules/asura-core/Application.h b/source/modules/asura-core/Application.h new file mode 100644 index 0000000..ea5faa7 --- /dev/null +++ b/source/modules/asura-core/Application.h @@ -0,0 +1,81 @@ +#ifndef _ASURA_ENGINE_APPLICATION_H_ +#define _ASURA_ENGINE_APPLICATION_H_ + +#include +#include +#include +#include + +#include "CoreConfig.h" + +namespace_begin(AsuraEngine) + +/// 子模块 +enum SubModules +{ + 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 = 0XFFFFFFFFU +}; + +/// +/// 管理主循环 +/// +class Application +{ +public: + + Application(); + + virtual ~Application(); + + /// + /// 初始化进入前的子系统 + /// + bool InitSubModules(uint flag = ASURA_MODULE_ALL); + + /// + /// 进入入口 + /// + virtual void Run(int argc, char* args[]); + + /// + /// 退出run时的处理 + /// + virtual void OnExit(); + +protected: + + /// + /// 添加module,application拥有module的所有权。 + /// + void EnqueueModule(Module* module); + +private: + + /// + /// 主线程的lua state handle,应用主循环在这里运行。一般上来说,只需要主线程有一个lua_State,其他线程不需要。在两个线程间 + /// 传递lua数据太痛苦了。任务在C++里面写,然后注册一个回调,而不是在另一个线程创建lua_State并注册函数,执行后发回数据 + /// 给主线程的lua_State。保证只有一个native实例之和一个lua_State绑定。 + /// + Luax::LuaxVM* m_VM; + + /// + /// 载入的Asura libs,会按照队列顺序初始化,并在退出时执行退出函数。 + /// + std::queue m_Modules; + +}; + +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/CoreConfig.h b/source/modules/asura-core/CoreConfig.h new file mode 100644 index 0000000..2dd0b03 --- /dev/null +++ b/source/modules/asura-core/CoreConfig.h @@ -0,0 +1,13 @@ +#ifndef _ASURA_CORE_CONFIG_H_ +#define _ASURA_CORE_CONFIG_H_ + +#define ASURA_WINDOW_SDL 1 + +#define ASURA_OPENGL_GLAD (1 << 1) +#define ASURA_OPENGL_GLEE (1 << 2) +#define ASURA_OPENGL_GLUT (1 << 3) +#define ASURA_OPENGL_LOADER (ASURA_OPENGL_GLAD|ASURA_OPENGL_GLEE|ASURA_OPENGL_GLUT) + +#define ASURA_GL_PROFILE 1 + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/CoreModule.cpp b/source/modules/asura-core/CoreModule.cpp new file mode 100644 index 0000000..93f8ca0 --- /dev/null +++ b/source/modules/asura-core/CoreModule.cpp @@ -0,0 +1,25 @@ +#include "CoreModule.h" + +using namespace AEThreading; +using namespace AEGraphics; + +namespace AsuraEngine +{ + + void CoreModule::Initialize(Luax::LuaxState& state) + { + // Graphics + LUAX_REGISTER_ABSTRACT_FACTORY(state, Texture); + LUAX_REGISTER_FACTORY(state, AEGraphics::Image); + // Wnd + LUAX_REGISTER_SINGLETON(state, AEWindow::Window); + // Threads + //LUAX_REGISTER_FACTORY(state, ThreadEx); + } + + void CoreModule::Finalize(Luax::LuaxState& state) + { + + } + +} \ No newline at end of file diff --git a/source/modules/asura-core/CoreModule.h b/source/modules/asura-core/CoreModule.h new file mode 100644 index 0000000..1781885 --- /dev/null +++ b/source/modules/asura-core/CoreModule.h @@ -0,0 +1,26 @@ +#ifndef _ASURA_CORE_MODULE_H_ +#define _ASURA_CORE_MODULE_H_ + +#include +#include + +#include "graphics/image.h" +#include "graphics/texture.h" +#include "window/window.h" +#include "Threads/ThreadEx.h" + +namespace_begin(AsuraEngine) + +class CoreModule : public Module +{ +public: + + void Initialize(Luax::LuaxState& state) override; + + void Finalize(Luax::LuaxState& state) override; + +}; + +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Font/Glyph.cpp b/source/modules/asura-core/Font/Glyph.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/Font/Glyph.h b/source/modules/asura-core/Font/Glyph.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/Font/String.cpp b/source/modules/asura-core/Font/String.cpp new file mode 100644 index 0000000..1731338 --- /dev/null +++ b/source/modules/asura-core/Font/String.cpp @@ -0,0 +1,376 @@ +//#include "String.hpp" +//#include "Utf.hpp" +// +//namespace AsuraEngine +//{ +// namespace Text +// { +// +// +// //////////////////////////////////////////////////////////// +// const std::size_t String::InvalidPos = std::basic_string::npos; +// +// +// //////////////////////////////////////////////////////////// +// String::String() +// { +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(char ansiChar, const std::locale& locale) +// { +// m_String += Utf32::DecodeAnsi(ansiChar, locale); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(wchar_t wideChar) +// { +// m_String += Utf32::DecodeWide(wideChar); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(uint32 utf32Char) +// { +// m_String += utf32Char; +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const char* ansiString, const std::locale& locale) +// { +// if (ansiString) +// { +// std::size_t length = strlen(ansiString); +// if (length > 0) +// { +// m_String.reserve(length + 1); +// Utf32::FromAnsi(ansiString, ansiString + length, std::back_inserter(m_String), locale); +// } +// } +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const std::string& ansiString, const std::locale& locale) +// { +// m_String.reserve(ansiString.length() + 1); +// Utf32::FromAnsi(ansiString.begin(), ansiString.end(), std::back_inserter(m_String), locale); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const wchar_t* wideString) +// { +// if (wideString) +// { +// std::size_t length = std::wcslen(wideString); +// if (length > 0) +// { +// m_String.reserve(length + 1); +// Utf32::FromWide(wideString, wideString + length, std::back_inserter(m_String)); +// } +// } +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const std::wstring& wideString) +// { +// m_String.reserve(wideString.length() + 1); +// Utf32::FromWide(wideString.begin(), wideString.end(), std::back_inserter(m_String)); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const uint32* utf32String) +// { +// if (utf32String) +// m_String = utf32String; +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const std::basic_string& utf32String) : +// m_String(utf32String) +// { +// } +// +// +// //////////////////////////////////////////////////////////// +// String::String(const String& copy) : +// m_String(copy.mString) +// { +// } +// +// +// //////////////////////////////////////////////////////////// +// String::operator std::string() const +// { +// return ToAnsiString(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::operator std::wstring() const +// { +// return ToWideString(); +// } +// +// +// //////////////////////////////////////////////////////////// +// std::string String::ToAnsiString(const std::locale& locale) const +// { +// // Prepare the output string +// std::string output; +// output.reserve(m_String.length() + 1); +// +// // Convert +// Utf32::ToAnsi(m_String.begin(), m_String.end(), std::back_inserter(output), 0, locale); +// +// return output; +// } +// +// +// //////////////////////////////////////////////////////////// +// std::wstring String::ToWideString() const +// { +// // Prepare the output string +// std::wstring output; +// output.reserve(m_String.length() + 1); +// +// // Convert +// Utf32::ToWide(m_String.begin(), m_String.end(), std::back_inserter(output), 0); +// +// return output; +// } +// +// +// //////////////////////////////////////////////////////////// +// std::basic_string String::ToUtf8() const +// { +// // Prepare the output string +// std::basic_string output; +// output.reserve(m_String.length()); +// +// // Convert +// Utf32::ToUtf8(m_String.begin(), m_String.end(), std::back_inserter(output)); +// +// return output; +// } +// +// +// //////////////////////////////////////////////////////////// +// std::basic_string String::ToUtf16() const +// { +// // Prepare the output string +// std::basic_string output; +// output.reserve(m_String.length()); +// +// // Convert +// Utf32::ToUtf16(m_String.begin(), m_String.end(), std::back_inserter(output)); +// +// return output; +// } +// +// +// //////////////////////////////////////////////////////////// +// std::basic_string String::ToUtf32() const +// { +// return m_String; +// } +// +// +// //////////////////////////////////////////////////////////// +// String& String::operator =(const String& right) +// { +// m_String = right.mString; +// return *this; +// } +// +// +// //////////////////////////////////////////////////////////// +// String& String::operator +=(const String& right) +// { +// m_String += right.mString; +// return *this; +// } +// +// +// //////////////////////////////////////////////////////////// +// uint32 String::operator [](std::size_t index) const +// { +// return m_String[index]; +// } +// +// +// //////////////////////////////////////////////////////////// +// uint32& String::operator [](std::size_t index) +// { +// return m_String[index]; +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Clear() +// { +// m_String.clear(); +// } +// +// +// //////////////////////////////////////////////////////////// +// std::size_t String::GetSize() const +// { +// return m_String.size(); +// } +// +// +// //////////////////////////////////////////////////////////// +// bool String::IsEmpty() const +// { +// return m_String.empty(); +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Erase(std::size_t position, std::size_t count) +// { +// m_String.erase(position, count); +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Insert(std::size_t position, const String& str) +// { +// m_String.insert(position, str.mString); +// } +// +// +// //////////////////////////////////////////////////////////// +// std::size_t String::Find(const String& str, std::size_t start) const +// { +// return m_String.find(str.mString, start); +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Replace(std::size_t position, std::size_t length, const String& replaceWith) +// { +// m_String.replace(position, length, replaceWith.mString); +// } +// +// +// //////////////////////////////////////////////////////////// +// void String::Replace(const String& searchFor, const String& replaceWith) +// { +// std::size_t step = replaceWith.GetSize(); +// std::size_t len = searchFor.GetSize(); +// std::size_t pos = Find(searchFor); +// +// // Replace each occurrence of search +// while (pos != InvalidPos) +// { +// Replace(pos, len, replaceWith); +// pos = Find(searchFor, pos + step); +// } +// } +// +// +// //////////////////////////////////////////////////////////// +// String String::Substring(std::size_t position, std::size_t length) const +// { +// return m_String.substr(position, length); +// } +// +// +// //////////////////////////////////////////////////////////// +// const uint32* String::GetData() const +// { +// return m_String.c_str(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::Iterator String::Begin() +// { +// return m_String.begin(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::ConstIterator String::Begin() const +// { +// return m_String.begin(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::Iterator String::End() +// { +// return m_String.end(); +// } +// +// +// //////////////////////////////////////////////////////////// +// String::ConstIterator String::End() const +// { +// return m_String.end(); +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator ==(const String& left, const String& right) +// { +// return left.mString == right.mString; +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator !=(const String& left, const String& right) +// { +// return !(left == right); +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator <(const String& left, const String& right) +// { +// return left.mString < right.mString; +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator >(const String& left, const String& right) +// { +// return right < left; +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator <=(const String& left, const String& right) +// { +// return !(right < left); +// } +// +// +// //////////////////////////////////////////////////////////// +// bool operator >=(const String& left, const String& right) +// { +// return !(left < right); +// } +// +// +// //////////////////////////////////////////////////////////// +// String operator +(const String& left, const String& right) +// { +// String string = left; +// string += right; +// +// return string; +// } +// +// +// } +//} diff --git a/source/modules/asura-core/Font/String.hpp b/source/modules/asura-core/Font/String.hpp new file mode 100644 index 0000000..13a8b2d --- /dev/null +++ b/source/modules/asura-core/Font/String.hpp @@ -0,0 +1,595 @@ +//#ifndef _ASURA_ENGINE_STRING_H_ +//#define _ASURA_ENGINE_STRING_H_ +// +//#include +// +//#include +//#include +//#include +// +//namespace AsuraEngine +//{ +// namespace Text +// { +// +// +// //////////////////////////////////////////////////////////// +// /// \brief Utility string class that automatically handles +// /// conversions between types and encodings +// /// +// //////////////////////////////////////////////////////////// +// class String +// { +// public: +// +// //////////////////////////////////////////////////////////// +// // Types +// //////////////////////////////////////////////////////////// +// typedef std::basic_string::iterator Iterator; ///< Iterator type +// typedef std::basic_string::const_iterator ConstIterator; ///< Read-only iterator type +// +// //////////////////////////////////////////////////////////// +// // Static member data +// //////////////////////////////////////////////////////////// +// static const std::size_t InvalidPos; ///< Represents an invalid position in the string +// +// //////////////////////////////////////////////////////////// +// /// \brief Default constructor +// /// +// /// This constructor creates an empty string. +// /// +// //////////////////////////////////////////////////////////// +// String(); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from a single ANSI character and a locale +// /// +// /// The source character is converted to UTF-32 according +// /// to the given locale. +// /// +// /// \param ansiChar ANSI character to convert +// /// \param locale Locale to use for conversion +// /// +// //////////////////////////////////////////////////////////// +// String(char ansiChar, const std::locale& locale = std::locale()); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from single wide character +// /// +// /// \param wideChar Wide character to convert +// /// +// //////////////////////////////////////////////////////////// +// String(wchar_t wideChar); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from single UTF-32 character +// /// +// /// \param utf32Char UTF-32 character to convert +// /// +// //////////////////////////////////////////////////////////// +// String(uint utf32Char); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from a null-terminated C-style ANSI string and a locale +// /// +// /// The source string is converted to UTF-32 according +// /// to the given locale. +// /// +// /// \param ansiString ANSI string to convert +// /// \param locale Locale to use for conversion +// /// +// //////////////////////////////////////////////////////////// +// String(const char* ansiString, const std::locale& locale = std::locale()); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from an ANSI string and a locale +// /// +// /// The source string is converted to UTF-32 according +// /// to the given locale. +// /// +// /// \param ansiString ANSI string to convert +// /// \param locale Locale to use for conversion +// /// +// //////////////////////////////////////////////////////////// +// String(const std::string& ansiString, const std::locale& locale = std::locale()); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from null-terminated C-style wide string +// /// +// /// \param wideString Wide string to convert +// /// +// //////////////////////////////////////////////////////////// +// String(const wchar_t* wideString); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from a wide string +// /// +// /// \param wideString Wide string to convert +// /// +// //////////////////////////////////////////////////////////// +// String(const std::wstring& wideString); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from a null-terminated C-style UTF-32 string +// /// +// /// \param utf32String UTF-32 string to assign +// /// +// //////////////////////////////////////////////////////////// +// String(const uint* utf32String); +// +// //////////////////////////////////////////////////////////// +// /// \brief Construct from an UTF-32 string +// /// +// /// \param utf32String UTF-32 string to assign +// /// +// //////////////////////////////////////////////////////////// +// String(const std::basic_string& utf32String); +// +// //////////////////////////////////////////////////////////// +// /// \brief Copy constructor +// /// +// /// \param copy Instance to copy +// /// +// //////////////////////////////////////////////////////////// +// String(const String& copy); +// +// //////////////////////////////////////////////////////////// +// /// \brief Create a new sf::String from a UTF-8 encoded string +// /// +// /// \param begin Forward iterator to the beginning of the UTF-8 sequence +// /// \param end Forward iterator to the end of the UTF-8 sequence +// /// +// /// \return A sf::String containing the source string +// /// +// /// \see fromUtf16, fromUtf32 +// /// +// //////////////////////////////////////////////////////////// +// template +// static String FromUtf8(T begin, T end); +// +// //////////////////////////////////////////////////////////// +// /// \brief Create a new sf::String from a UTF-16 encoded string +// /// +// /// \param begin Forward iterator to the beginning of the UTF-16 sequence +// /// \param end Forward iterator to the end of the UTF-16 sequence +// /// +// /// \return A sf::String containing the source string +// /// +// /// \see fromUtf8, fromUtf32 +// /// +// //////////////////////////////////////////////////////////// +// template +// static String FromUtf16(T begin, T end); +// +// //////////////////////////////////////////////////////////// +// /// \brief Create a new sf::String from a UTF-32 encoded string +// /// +// /// This function is provided for consistency, it is equivalent to +// /// using the constructors that takes a const sf::uint* or +// /// a std::basic_string. +// /// +// /// \param begin Forward iterator to the beginning of the UTF-32 sequence +// /// \param end Forward iterator to the end of the UTF-32 sequence +// /// +// /// \return A sf::String containing the source string +// /// +// /// \see fromUtf8, fromUtf16 +// /// +// //////////////////////////////////////////////////////////// +// template +// static String FromUtf32(T begin, T end); +// +// //////////////////////////////////////////////////////////// +// /// \brief Implicit conversion operator to std::string (ANSI string) +// /// +// /// The current global locale is used for conversion. If you +// /// want to explicitly specify a locale, see toAnsiString. +// /// Characters that do not fit in the target encoding are +// /// discarded from the returned string. +// /// This operator is defined for convenience, and is equivalent +// /// to calling toAnsiString(). +// /// +// /// \return Converted ANSI string +// /// +// /// \see toAnsiString, operator std::wstring +// /// +// //////////////////////////////////////////////////////////// +// operator std::string() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Implicit conversion operator to std::wstring (wide string) +// /// +// /// Characters that do not fit in the target encoding are +// /// discarded from the returned string. +// /// This operator is defined for convenience, and is equivalent +// /// to calling toWideString(). +// /// +// /// \return Converted wide string +// /// +// /// \see toWideString, operator std::string +// /// +// //////////////////////////////////////////////////////////// +// operator std::wstring() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to an ANSI string +// /// +// /// The UTF-32 string is converted to an ANSI string in +// /// the encoding defined by \a locale. +// /// Characters that do not fit in the target encoding are +// /// discarded from the returned string. +// /// +// /// \param locale Locale to use for conversion +// /// +// /// \return Converted ANSI string +// /// +// /// \see toWideString, operator std::string +// /// +// //////////////////////////////////////////////////////////// +// std::string ToAnsiString(const std::locale& locale = std::locale()) const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to a wide string +// /// +// /// Characters that do not fit in the target encoding are +// /// discarded from the returned string. +// /// +// /// \return Converted wide string +// /// +// /// \see toAnsiString, operator std::wstring +// /// +// //////////////////////////////////////////////////////////// +// std::wstring ToWideString() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to a UTF-8 string +// /// +// /// \return Converted UTF-8 string +// /// +// /// \see toUtf16, toUtf32 +// /// +// //////////////////////////////////////////////////////////// +// std::basic_string ToUtf8() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to a UTF-16 string +// /// +// /// \return Converted UTF-16 string +// /// +// /// \see toUtf8, toUtf32 +// /// +// //////////////////////////////////////////////////////////// +// std::basic_string ToUtf16() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Convert the Unicode string to a UTF-32 string +// /// +// /// This function doesn't perform any conversion, since the +// /// string is already stored as UTF-32 internally. +// /// +// /// \return Converted UTF-32 string +// /// +// /// \see toUtf8, toUtf16 +// /// +// //////////////////////////////////////////////////////////// +// std::basic_string ToUtf32() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Overload of assignment operator +// /// +// /// \param right Instance to assign +// /// +// /// \return Reference to self +// /// +// //////////////////////////////////////////////////////////// +// String& operator =(const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \brief Overload of += operator to append an UTF-32 string +// /// +// /// \param right String to append +// /// +// /// \return Reference to self +// /// +// //////////////////////////////////////////////////////////// +// String& operator +=(const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \brief Overload of [] operator to access a character by its position +// /// +// /// This function provides read-only access to characters. +// /// Note: the behavior is undefined if \a index is out of range. +// /// +// /// \param index Index of the character to get +// /// +// /// \return Character at position \a index +// /// +// //////////////////////////////////////////////////////////// +// uint operator [](std::size_t index) const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Overload of [] operator to access a character by its position +// /// +// /// This function provides read and write access to characters. +// /// Note: the behavior is undefined if \a index is out of range. +// /// +// /// \param index Index of the character to get +// /// +// /// \return Reference to the character at position \a index +// /// +// //////////////////////////////////////////////////////////// +// uint& operator [](std::size_t index); +// +// //////////////////////////////////////////////////////////// +// /// \brief Clear the string +// /// +// /// This function removes all the characters from the string. +// /// +// /// \see isEmpty, erase +// /// +// //////////////////////////////////////////////////////////// +// void Clear(); +// +// //////////////////////////////////////////////////////////// +// /// \brief Get the size of the string +// /// +// /// \return Number of characters in the string +// /// +// /// \see isEmpty +// /// +// //////////////////////////////////////////////////////////// +// std::size_t GetSize() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Check whether the string is empty or not +// /// +// /// \return True if the string is empty (i.e. contains no character) +// /// +// /// \see clear, getSize +// /// +// //////////////////////////////////////////////////////////// +// bool IsEmpty() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Erase one or more characters from the string +// /// +// /// This function removes a sequence of \a count characters +// /// starting from \a position. +// /// +// /// \param position Position of the first character to erase +// /// \param count Number of characters to erase +// /// +// //////////////////////////////////////////////////////////// +// void Erase(std::size_t position, std::size_t count = 1); +// +// //////////////////////////////////////////////////////////// +// /// \brief Insert one or more characters into the string +// /// +// /// This function inserts the characters of \a str +// /// into the string, starting from \a position. +// /// +// /// \param position Position of insertion +// /// \param str Characters to insert +// /// +// //////////////////////////////////////////////////////////// +// void Insert(std::size_t position, const String& str); +// +// //////////////////////////////////////////////////////////// +// /// \brief Find a sequence of one or more characters in the string +// /// +// /// This function searches for the characters of \a str +// /// in the string, starting from \a start. +// /// +// /// \param str Characters to find +// /// \param start Where to begin searching +// /// +// /// \return Position of \a str in the string, or String::InvalidPos if not found +// /// +// //////////////////////////////////////////////////////////// +// std::size_t Find(const String& str, std::size_t start = 0) const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Replace a substring with another string +// /// +// /// This function replaces the substring that starts at index \a position +// /// and spans \a length characters with the string \a replaceWith. +// /// +// /// \param position Index of the first character to be replaced +// /// \param length Number of characters to replace. You can pass InvalidPos to +// /// replace all characters until the end of the string. +// /// \param replaceWith String that replaces the given substring. +// /// +// //////////////////////////////////////////////////////////// +// void Replace(std::size_t position, std::size_t length, const String& replaceWith); +// +// //////////////////////////////////////////////////////////// +// /// \brief Replace all occurrences of a substring with a replacement string +// /// +// /// This function replaces all occurrences of \a searchFor in this string +// /// with the string \a replaceWith. +// /// +// /// \param searchFor The value being searched for +// /// \param replaceWith The value that replaces found \a searchFor values +// /// +// //////////////////////////////////////////////////////////// +// void Replace(const String& searchFor, const String& replaceWith); +// +// //////////////////////////////////////////////////////////// +// /// \brief Return a part of the string +// /// +// /// This function returns the substring that starts at index \a position +// /// and spans \a length characters. +// /// +// /// \param position Index of the first character +// /// \param length Number of characters to include in the substring (if +// /// the string is shorter, as many characters as possible +// /// are included). \ref InvalidPos can be used to include all +// /// characters until the end of the string. +// /// +// /// \return String object containing a substring of this object +// /// +// //////////////////////////////////////////////////////////// +// String Substring(std::size_t position, std::size_t length = InvalidPos) const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Get a pointer to the C-style array of characters +// /// +// /// This functions provides a read-only access to a +// /// null-terminated C-style representation of the string. +// /// The returned pointer is temporary and is meant only for +// /// immediate use, thus it is not recommended to store it. +// /// +// /// \return Read-only pointer to the array of characters +// /// +// //////////////////////////////////////////////////////////// +// const uint* GetData() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Return an iterator to the beginning of the string +// /// +// /// \return Read-write iterator to the beginning of the string characters +// /// +// /// \see end +// /// +// //////////////////////////////////////////////////////////// +// Iterator Begin(); +// +// //////////////////////////////////////////////////////////// +// /// \brief Return an iterator to the beginning of the string +// /// +// /// \return Read-only iterator to the beginning of the string characters +// /// +// /// \see end +// /// +// //////////////////////////////////////////////////////////// +// ConstIterator Begin() const; +// +// //////////////////////////////////////////////////////////// +// /// \brief Return an iterator to the end of the string +// /// +// /// The end iterator refers to 1 position past the last character; +// /// thus it represents an invalid character and should never be +// /// accessed. +// /// +// /// \return Read-write iterator to the end of the string characters +// /// +// /// \see begin +// /// +// //////////////////////////////////////////////////////////// +// Iterator End(); +// +// //////////////////////////////////////////////////////////// +// /// \brief Return an iterator to the end of the string +// /// +// /// The end iterator refers to 1 position past the last character; +// /// thus it represents an invalid character and should never be +// /// accessed. +// /// +// /// \return Read-only iterator to the end of the string characters +// /// +// /// \see begin +// /// +// //////////////////////////////////////////////////////////// +// ConstIterator End() const; +// +// private: +// +// friend bool operator ==(const String& left, const String& right); +// friend bool operator <(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// // Member data +// //////////////////////////////////////////////////////////// +// std::basic_string m_String; ///< Internal string of UTF-32 characters +// }; +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of == operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if both strings are equal +// /// +// //////////////////////////////////////////////////////////// +// bool operator ==(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of != operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if both strings are different +// /// +// //////////////////////////////////////////////////////////// +// bool operator !=(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of < operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if \a left is lexicographically before \a right +// /// +// //////////////////////////////////////////////////////////// +// bool operator <(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of > operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if \a left is lexicographically after \a right +// /// +// //////////////////////////////////////////////////////////// +// bool operator >(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of <= operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if \a left is lexicographically before or equivalent to \a right +// /// +// //////////////////////////////////////////////////////////// +// bool operator <=(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of >= operator to compare two UTF-32 strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return True if \a left is lexicographically after or equivalent to \a right +// /// +// //////////////////////////////////////////////////////////// +// bool operator >=(const String& left, const String& right); +// +// //////////////////////////////////////////////////////////// +// /// \relates String +// /// \brief Overload of binary + operator to concatenate two strings +// /// +// /// \param left Left operand (a string) +// /// \param right Right operand (a string) +// /// +// /// \return Concatenated string +// /// +// //////////////////////////////////////////////////////////// +// String operator +(const String& left, const String& right); +// +// #include "String.inc" +// +// } +//} +// +//#endif \ No newline at end of file diff --git a/source/modules/asura-core/Font/String.inc b/source/modules/asura-core/Font/String.inc new file mode 100644 index 0000000..ef18228 --- /dev/null +++ b/source/modules/asura-core/Font/String.inc @@ -0,0 +1,29 @@ + +//////////////////////////////////////////////////////////// +template +String String::fromUtf8(T begin, T end) +{ + String string; + Utf8::toUtf32(begin, end, std::back_inserter(string.m_string)); + return string; +} + + +//////////////////////////////////////////////////////////// +template +String String::fromUtf16(T begin, T end) +{ + String string; + Utf16::toUtf32(begin, end, std::back_inserter(string.m_string)); + return string; +} + + +//////////////////////////////////////////////////////////// +template +String String::fromUtf32(T begin, T end) +{ + String string; + string.m_string.assign(begin, end); + return string; +} diff --git a/source/modules/asura-core/Font/TTF.cpp b/source/modules/asura-core/Font/TTF.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/Font/TTF.h b/source/modules/asura-core/Font/TTF.h new file mode 100644 index 0000000..b83cf76 --- /dev/null +++ b/source/modules/asura-core/Font/TTF.h @@ -0,0 +1,17 @@ +#ifndef _ASURA_TTF_H_ +#define _ASURA_TTF_H_ + +namespace AsuraEngine +{ + namespace Text + { + + class TTF + { + + }; + + } +} + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Font/Utf.hpp b/source/modules/asura-core/Font/Utf.hpp new file mode 100644 index 0000000..59f62ed --- /dev/null +++ b/source/modules/asura-core/Font/Utf.hpp @@ -0,0 +1,720 @@ +#ifndef _ASURA_UTF_HPP_ +#define _ASURA_UTF_HPP_ + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include + +namespace AsuraEngine +{ + namespace Text + { + + template + class Utf; + + //////////////////////////////////////////////////////////// + /// \brief Specialization of the Utf template for UTF-8 + /// + //////////////////////////////////////////////////////////// + template <> + class Utf<8> + { + public: + + //////////////////////////////////////////////////////////// + /// \brief Decode a single UTF-8 character + /// + /// Decoding a character means finding its unique 32-bits + /// code (called the codepoint) in the Unicode standard. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Codepoint of the decoded UTF-8 character + /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-8 character + /// + /// Encoding a character means converting a unique 32-bits + /// code (called the codepoint) in the target encoding, UTF-8. + /// + /// \param input Codepoint to encode as UTF-8 + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to UTF-8 (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out Encode(Uint32 input, Out output, Uint8 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Advance to the next UTF-8 character + /// + /// This function is necessary for multi-elements encodings, as + /// a single character may use more than 1 storage element. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static In Next(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Count the number of characters of a UTF-8 sequence + /// + /// This function is necessary for multi-elements encodings, as + /// a single character may use more than 1 storage element, thus the + /// total size can be different from (begin - end). + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static std::size_t Count(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Convert an ANSI characters range to UTF-8 + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert a wide characters range to UTF-8 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromWide(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-8 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromLatin1(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-8 characters range to ANSI characters + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-8 characters range to wide characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-8 characters range to latin-1 (ISO-5589-1) characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToLatin1(In begin, In end, Out output, char replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-8 characters range to UTF-8 + /// + /// This functions does nothing more than a direct copy; + /// it is defined only to provide the same interface as other + /// specializations of the sf::Utf<> template, and allow + /// generic code to be written on top of it. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf8(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-8 characters range to UTF-16 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf16(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-8 characters range to UTF-32 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf32(In begin, In end, Out output); + }; + + //////////////////////////////////////////////////////////// + /// \brief Specialization of the Utf template for UTF-16 + /// + //////////////////////////////////////////////////////////// + template <> + class Utf<16> + { + public: + + //////////////////////////////////////////////////////////// + /// \brief Decode a single UTF-16 character + /// + /// Decoding a character means finding its unique 32-bits + /// code (called the codepoint) in the Unicode standard. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Codepoint of the decoded UTF-16 character + /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-16 character + /// + /// Encoding a character means converting a unique 32-bits + /// code (called the codepoint) in the target encoding, UTF-16. + /// + /// \param input Codepoint to encode as UTF-16 + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to UTF-16 (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out Encode(Uint32 input, Out output, Uint16 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Advance to the next UTF-16 character + /// + /// This function is necessary for multi-elements encodings, as + /// a single character may use more than 1 storage element. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static In Next(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Count the number of characters of a UTF-16 sequence + /// + /// This function is necessary for multi-elements encodings, as + /// a single character may use more than 1 storage element, thus the + /// total size can be different from (begin - end). + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static std::size_t Count(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Convert an ANSI characters range to UTF-16 + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert a wide characters range to UTF-16 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromWide(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-16 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromLatin1(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-16 characters range to ANSI characters + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-16 characters range to wide characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToLatin1(In begin, In end, Out output, char replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-16 characters range to UTF-8 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf8(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-16 characters range to UTF-16 + /// + /// This functions does nothing more than a direct copy; + /// it is defined only to provide the same interface as other + /// specializations of the sf::Utf<> template, and allow + /// generic code to be written on top of it. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf16(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-16 characters range to UTF-32 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf32(In begin, In end, Out output); + }; + + //////////////////////////////////////////////////////////// + /// \brief Specialization of the Utf template for UTF-32 + /// + //////////////////////////////////////////////////////////// + template <> + class Utf<32> + { + public: + + //////////////////////////////////////////////////////////// + /// \brief Decode a single UTF-32 character + /// + /// Decoding a character means finding its unique 32-bits + /// code (called the codepoint) in the Unicode standard. + /// For UTF-32, the character value is the same as the codepoint. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Codepoint of the decoded UTF-32 character + /// \param replacement Replacement character to use in case the UTF-8 sequence is invalid + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static In Decode(In begin, In end, Uint32& output, Uint32 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-32 character + /// + /// Encoding a character means converting a unique 32-bits + /// code (called the codepoint) in the target encoding, UTF-32. + /// For UTF-32, the codepoint is the same as the character value. + /// + /// \param input Codepoint to encode as UTF-32 + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to UTF-32 (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out Encode(Uint32 input, Out output, Uint32 replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Advance to the next UTF-32 character + /// + /// This function is trivial for UTF-32, which can store + /// every character in a single storage element. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static In Next(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Count the number of characters of a UTF-32 sequence + /// + /// This function is trivial for UTF-32, which can store + /// every character in a single storage element. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// + /// \return Iterator pointing to one past the last read element of the input sequence + /// + //////////////////////////////////////////////////////////// + template + static std::size_t Count(In begin, In end); + + //////////////////////////////////////////////////////////// + /// \brief Convert an ANSI characters range to UTF-32 + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromAnsi(In begin, In end, Out output, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert a wide characters range to UTF-32 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromWide(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a latin-1 (ISO-5589-1) characters range to UTF-32 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out FromLatin1(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-32 characters range to ANSI characters + /// + /// The current global locale will be used by default, unless you + /// pass a custom one in the \a locale parameter. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to ANSI (use 0 to skip them) + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToAnsi(In begin, In end, Out output, char replacement = 0, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-32 characters range to wide characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToWide(In begin, In end, Out output, wchar_t replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert an UTF-16 characters range to latin-1 (ISO-5589-1) characters + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement for characters not convertible to wide (use 0 to skip them) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToLatin1(In begin, In end, Out output, char replacement = 0); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-32 characters range to UTF-8 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf8(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-32 characters range to UTF-16 + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf16(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Convert a UTF-32 characters range to UTF-32 + /// + /// This functions does nothing more than a direct copy; + /// it is defined only to provide the same interface as other + /// specializations of the sf::Utf<> template, and allow + /// generic code to be written on top of it. + /// + /// \param begin Iterator pointing to the beginning of the input sequence + /// \param end Iterator pointing to the end of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ToUtf32(In begin, In end, Out output); + + //////////////////////////////////////////////////////////// + /// \brief Decode a single ANSI character to UTF-32 + /// + /// This function does not exist in other specializations + /// of sf::Utf<>, it is defined for convenience (it is used by + /// several other conversion functions). + /// + /// \param input Input ANSI character + /// \param locale Locale to use for conversion + /// + /// \return Converted character + /// + //////////////////////////////////////////////////////////// + template + static Uint32 DecodeAnsi(In input, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Decode a single wide character to UTF-32 + /// + /// This function does not exist in other specializations + /// of sf::Utf<>, it is defined for convenience (it is used by + /// several other conversion functions). + /// + /// \param input Input wide character + /// + /// \return Converted character + /// + //////////////////////////////////////////////////////////// + template + static Uint32 DecodeWide(In input); + + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-32 character to ANSI + /// + /// This function does not exist in other specializations + /// of sf::Utf<>, it is defined for convenience (it is used by + /// several other conversion functions). + /// + /// \param codepoint Iterator pointing to the beginning of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement if the input character is not convertible to ANSI (use 0 to skip it) + /// \param locale Locale to use for conversion + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out EncodeAnsi(Uint32 codepoint, Out output, char replacement = 0, const std::locale& locale = std::locale()); + + //////////////////////////////////////////////////////////// + /// \brief Encode a single UTF-32 character to wide + /// + /// This function does not exist in other specializations + /// of sf::Utf<>, it is defined for convenience (it is used by + /// several other conversion functions). + /// + /// \param codepoint Iterator pointing to the beginning of the input sequence + /// \param output Iterator pointing to the beginning of the output sequence + /// \param replacement Replacement if the input character is not convertible to wide (use 0 to skip it) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out EncodeWide(Uint32 codepoint, Out output, wchar_t replacement = 0); + }; + +#include "Utf.inc" + + // Make typedefs to get rid of the template syntax + typedef Utf<8> Utf8; + typedef Utf<16> Utf16; + typedef Utf<32> Utf32; + + } // namespace sf + +} + + +#endif // SFML_UTF_HPP diff --git a/source/modules/asura-core/Font/Utf.inc b/source/modules/asura-core/Font/Utf.inc new file mode 100644 index 0000000..69a523b --- /dev/null +++ b/source/modules/asura-core/Font/Utf.inc @@ -0,0 +1,752 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2019 Laurent Gomila (laurent@sfml-dev.org) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////// +// References: +// +// https://www.unicode.org/ +// https://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.c +// https://www.unicode.org/Public/PROGRAMS/CVTUTF/ConvertUTF.h +// https://people.w3.org/rishida/scripts/uniview/conversion +// +//////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////// +template +In Utf<8>::Decode(In begin, In end, Uint32& output, Uint32 replacement) +{ + // Some useful precomputed data + static const int trailing[256] = + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5 + }; + static const Uint32 offsets[6] = + { + 0x00000000, 0x00003080, 0x000E2080, 0x03C82080, 0xFA082080, 0x82082080 + }; + + // decode the character + int trailingBytes = trailing[static_cast(*begin)]; + if (begin + trailingBytes < end) + { + output = 0; + switch (trailingBytes) + { + case 5: output += static_cast(*begin++); output <<= 6; + case 4: output += static_cast(*begin++); output <<= 6; + case 3: output += static_cast(*begin++); output <<= 6; + case 2: output += static_cast(*begin++); output <<= 6; + case 1: output += static_cast(*begin++); output <<= 6; + case 0: output += static_cast(*begin++); + } + output -= offsets[trailingBytes]; + } + else + { + // Incomplete character + begin = end; + output = replacement; + } + + return begin; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<8>::Encode(Uint32 input, Out output, Uint8 replacement) +{ + // Some useful precomputed data + static const Uint8 firstBytes[7] = + { + 0x00, 0x00, 0xC0, 0xE0, 0xF0, 0xF8, 0xFC + }; + + // encode the character + if ((input > 0x0010FFFF) || ((input >= 0xD800) && (input <= 0xDBFF))) + { + // Invalid character + if (replacement) + *output++ = replacement; + } + else + { + // Valid character + + // Get the number of bytes to write + std::size_t bytestoWrite = 1; + if (input < 0x80) bytestoWrite = 1; + else if (input < 0x800) bytestoWrite = 2; + else if (input < 0x10000) bytestoWrite = 3; + else if (input <= 0x0010FFFF) bytestoWrite = 4; + + // Extract the bytes to write + Uint8 bytes[4]; + switch (bytestoWrite) + { + case 4: bytes[3] = static_cast((input | 0x80) & 0xBF); input >>= 6; + case 3: bytes[2] = static_cast((input | 0x80) & 0xBF); input >>= 6; + case 2: bytes[1] = static_cast((input | 0x80) & 0xBF); input >>= 6; + case 1: bytes[0] = static_cast (input | firstBytes[bytestoWrite]); + } + + // Add them to the output + output = std::copy(bytes, bytes + bytestoWrite, output); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +In Utf<8>::Next(In begin, In end) +{ + Uint32 codepoint; + return Decode(begin, end, codepoint); +} + + +//////////////////////////////////////////////////////////// +template +std::size_t Utf<8>::Count(In begin, In end) +{ + std::size_t length = 0; + while (begin < end) + { + begin = Next(begin, end); + ++length; + } + + return length; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<8>::FromAnsi(In begin, In end, Out output, const std::locale& locale) +{ + while (begin < end) + { + Uint32 codepoint = Utf<32>::DecodeAnsi(*begin++, locale); + output = Encode(codepoint, output); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<8>::FromWide(In begin, In end, Out output) +{ + while (begin < end) + { + Uint32 codepoint = Utf<32>::DecodeWide(*begin++); + output = Encode(codepoint, output); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<8>::FromLatin1(In begin, In end, Out output) +{ + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + while (begin < end) + output = Encode(*begin++, output); + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<8>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) +{ + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<32>::EncodeAnsi(codepoint, output, replacement, locale); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<8>::ToWide(In begin, In end, Out output, wchar_t replacement) +{ + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<32>::EncodeWide(codepoint, output, replacement); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<8>::ToLatin1(In begin, In end, Out output, char replacement) +{ + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + *output++ = codepoint < 256 ? static_cast(codepoint) : replacement; + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<8>::ToUtf8(In begin, In end, Out output) +{ + return std::copy(begin, end, output); +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<8>::ToUtf16(In begin, In end, Out output) +{ + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<16>::Encode(codepoint, output); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<8>::ToUtf32(In begin, In end, Out output) +{ + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + *output++ = codepoint; + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +In Utf<16>::Decode(In begin, In end, Uint32& output, Uint32 replacement) +{ + Uint16 first = *begin++; + + // If it's a surrogate pair, first convert to a single UTF-32 character + if ((first >= 0xD800) && (first <= 0xDBFF)) + { + if (begin < end) + { + Uint32 second = *begin++; + if ((second >= 0xDC00) && (second <= 0xDFFF)) + { + // The second element is valid: convert the two elements to a UTF-32 character + output = ((first - 0xD800) << 10) + (second - 0xDC00) + 0x0010000; + } + else + { + // Invalid character + output = replacement; + } + } + else + { + // Invalid character + begin = end; + output = replacement; + } + } + else + { + // We can make a direct copy + output = first; + } + + return begin; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<16>::Encode(Uint32 input, Out output, Uint16 replacement) +{ + if (input <= 0xFFFF) + { + // The character can be copied directly, we just need to check if it's in the valid range + if ((input >= 0xD800) && (input <= 0xDFFF)) + { + // Invalid character (this range is reserved) + if (replacement) + *output++ = replacement; + } + else + { + // Valid character directly convertible to a single UTF-16 character + *output++ = static_cast(input); + } + } + else if (input > 0x0010FFFF) + { + // Invalid character (greater than the maximum Unicode value) + if (replacement) + *output++ = replacement; + } + else + { + // The input character will be converted to two UTF-16 elements + input -= 0x0010000; + *output++ = static_cast((input >> 10) + 0xD800); + *output++ = static_cast((input & 0x3FFUL) + 0xDC00); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +In Utf<16>::Next(In begin, In end) +{ + Uint32 codepoint; + return Decode(begin, end, codepoint); +} + + +//////////////////////////////////////////////////////////// +template +std::size_t Utf<16>::Count(In begin, In end) +{ + std::size_t length = 0; + while (begin < end) + { + begin = Next(begin, end); + ++length; + } + + return length; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<16>::FromAnsi(In begin, In end, Out output, const std::locale& locale) +{ + while (begin < end) + { + Uint32 codepoint = Utf<32>::DecodeAnsi(*begin++, locale); + output = Encode(codepoint, output); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<16>::FromWide(In begin, In end, Out output) +{ + while (begin < end) + { + Uint32 codepoint = Utf<32>::DecodeWide(*begin++); + output = Encode(codepoint, output); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<16>::FromLatin1(In begin, In end, Out output) +{ + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + return std::copy(begin, end, output); +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<16>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) +{ + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<32>::EncodeAnsi(codepoint, output, replacement, locale); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<16>::ToWide(In begin, In end, Out output, wchar_t replacement) +{ + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<32>::EncodeWide(codepoint, output, replacement); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<16>::ToLatin1(In begin, In end, Out output, char replacement) +{ + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + while (begin < end) + { + *output++ = *begin < 256 ? static_cast(*begin) : replacement; + begin++; + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<16>::ToUtf8(In begin, In end, Out output) +{ + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + output = Utf<8>::Encode(codepoint, output); + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<16>::ToUtf16(In begin, In end, Out output) +{ + return std::copy(begin, end, output); +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<16>::ToUtf32(In begin, In end, Out output) +{ + while (begin < end) + { + Uint32 codepoint; + begin = Decode(begin, end, codepoint); + *output++ = codepoint; + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +In Utf<32>::Decode(In begin, In /*end*/, Uint32& output, Uint32 /*replacement*/) +{ + output = *begin++; + return begin; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<32>::Encode(Uint32 input, Out output, Uint32 /*replacement*/) +{ + *output++ = input; + return output; +} + + +//////////////////////////////////////////////////////////// +template +In Utf<32>::Next(In begin, In /*end*/) +{ + return ++begin; +} + + +//////////////////////////////////////////////////////////// +template +std::size_t Utf<32>::Count(In begin, In end) +{ + return begin - end; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<32>::FromAnsi(In begin, In end, Out output, const std::locale& locale) +{ + while (begin < end) + *output++ = DecodeAnsi(*begin++, locale); + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<32>::FromWide(In begin, In end, Out output) +{ + while (begin < end) + *output++ = DecodeWide(*begin++); + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<32>::FromLatin1(In begin, In end, Out output) +{ + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + return std::copy(begin, end, output); +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<32>::ToAnsi(In begin, In end, Out output, char replacement, const std::locale& locale) +{ + while (begin < end) + output = EncodeAnsi(*begin++, output, replacement, locale); + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<32>::ToWide(In begin, In end, Out output, wchar_t replacement) +{ + while (begin < end) + output = EncodeWide(*begin++, output, replacement); + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<32>::ToLatin1(In begin, In end, Out output, char replacement) +{ + // Latin-1 is directly compatible with Unicode encodings, + // and can thus be treated as (a sub-range of) UTF-32 + while (begin < end) + { + *output++ = *begin < 256 ? static_cast(*begin) : replacement; + begin++; + } + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<32>::ToUtf8(In begin, In end, Out output) +{ + while (begin < end) + output = Utf<8>::Encode(*begin++, output); + + return output; +} + +//////////////////////////////////////////////////////////// +template +Out Utf<32>::ToUtf16(In begin, In end, Out output) +{ + while (begin < end) + output = Utf<16>::Encode(*begin++, output); + + return output; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<32>::ToUtf32(In begin, In end, Out output) +{ + return std::copy(begin, end, output); +} + + +//////////////////////////////////////////////////////////// +template +Uint32 Utf<32>::DecodeAnsi(In input, const std::locale& locale) +{ + // On Windows, GCC's standard library (glibc++) has almost + // no support for Unicode stuff. As a consequence, in this + // context we can only use the default locale and ignore + // the one passed as parameter. + + #if defined(SFML_SYSTEM_WINDOWS) && /* if Windows ... */ \ + (defined(__GLIBCPP__) || defined (__GLIBCXX__)) && /* ... and standard library is glibc++ ... */ \ + !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) /* ... and STLPort is not used on top of it */ + + (void)locale; // to avoid warnings + + wchar_t character = 0; + mbtowc(&character, &input, 1); + return static_cast(character); + + #else + + // Get the facet of the locale which deals with character conversion + const std::ctype& facet = std::use_facet< std::ctype >(locale); + + // Use the facet to convert each character of the input string + return static_cast(facet.widen(input)); + + #endif +} + + +//////////////////////////////////////////////////////////// +template +Uint32 Utf<32>::DecodeWide(In input) +{ + // The encoding of wide characters is not well defined and is left to the system; + // however we can safely assume that it is UCS-2 on Windows and + // UCS-4 on Unix systems. + // In both cases, a simple copy is enough (UCS-2 is a subset of UCS-4, + // and UCS-4 *is* UTF-32). + + return input; +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<32>::EncodeAnsi(Uint32 codepoint, Out output, char replacement, const std::locale& locale) +{ + // On Windows, gcc's standard library (glibc++) has almost + // no support for Unicode stuff. As a consequence, in this + // context we can only use the default locale and ignore + // the one passed as parameter. + + #if defined(SFML_SYSTEM_WINDOWS) && /* if Windows ... */ \ + (defined(__GLIBCPP__) || defined (__GLIBCXX__)) && /* ... and standard library is glibc++ ... */ \ + !(defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) /* ... and STLPort is not used on top of it */ + + (void)locale; // to avoid warnings + + char character = 0; + if (wctomb(&character, static_cast(codepoint)) >= 0) + *output++ = character; + else if (replacement) + *output++ = replacement; + + return output; + + #else + + // Get the facet of the locale which deals with character conversion + const std::ctype& facet = std::use_facet< std::ctype >(locale); + + // Use the facet to convert each character of the input string + *output++ = facet.narrow(static_cast(codepoint), replacement); + + return output; + + #endif +} + + +//////////////////////////////////////////////////////////// +template +Out Utf<32>::EncodeWide(Uint32 codepoint, Out output, wchar_t replacement) +{ + // The encoding of wide characters is not well defined and is left to the system; + // however we can safely assume that it is UCS-2 on Windows and + // UCS-4 on Unix systems. + // For UCS-2 we need to check if the source characters fits in (UCS-2 is a subset of UCS-4). + // For UCS-4 we can do a direct copy (UCS-4 *is* UTF-32). + + switch (sizeof(wchar_t)) + { + case 4: + { + *output++ = static_cast(codepoint); + break; + } + + default: + { + if ((codepoint <= 0xFFFF) && ((codepoint < 0xD800) || (codepoint > 0xDFFF))) + { + *output++ = static_cast(codepoint); + } + else if (replacement) + { + *output++ = replacement; + } + break; + } + } + + return output; +} diff --git a/source/modules/asura-core/Graphics/BlendMode.h b/source/modules/asura-core/Graphics/BlendMode.h new file mode 100644 index 0000000..7a31eed --- /dev/null +++ b/source/modules/asura-core/Graphics/BlendMode.h @@ -0,0 +1,17 @@ +#ifndef _ASURA_ENGINE_BLEND_MODE_H_ +#define _ASURA_ENGINE_BLEND_MODE_H_ + +#include + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +enum BlendMode +{ + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Canvas.cpp b/source/modules/asura-core/Graphics/Canvas.cpp new file mode 100644 index 0000000..60c8f87 --- /dev/null +++ b/source/modules/asura-core/Graphics/Canvas.cpp @@ -0,0 +1,49 @@ +#include "Canvas.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +Canvas::Canvas() + : m_Width(0) + , m_Height(0) + , m_FBO(0) +{ + // Fix: 等设置大小初始化时再申请framebuffer资源。 + //glGenFramebuffers(1, &m_FBO); + //GLint current_fbo; + //glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); + //glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); + //glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TexID, 0); + //glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); +} + +void Canvas::SetSize(uint w, uint h) +{ + if (m_FBO == 0) + { + glGenFramebuffers(1, &m_FBO); + if (m_FBO == 0) + throw Exception("OpenGL glGenFramebuffers cannot generate frame buffer object."); + // 申请纹理 + if (m_TexID == 0) + { + glGenTextures(1, &m_TexID); + if (m_TexID == 0) + throw Exception("OpenGL glGenTextures cannot generate texture."); + } + GLint current_fbo; + glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, ¤t_fbo); + glBindFramebuffer(GL_FRAMEBUFFER, m_FBO); + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_TexID, 0); + glBindFramebuffer(GL_FRAMEBUFFER, current_fbo); + } + GLint current_tex; + glGetIntegerv(GL_TEXTURE_BINDING_2D, ¤t_tex); + glBindTexture(GL_TEXTURE_2D, m_TexID); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); + glBindTexture(GL_TEXTURE_2D, current_tex); +} + +namespace_end + +namespace_end \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Canvas.h b/source/modules/asura-core/Graphics/Canvas.h new file mode 100644 index 0000000..0ec55bc --- /dev/null +++ b/source/modules/asura-core/Graphics/Canvas.h @@ -0,0 +1,73 @@ +#ifndef _ASURA_ENGINE_CANVAS_H_ +#define _ASURA_ENGINE_CANVAS_H_ + +#include +#include +#include +#include + +#include "GfxDevice.h" +#include "Texture.h" +#include "RenderTarget.h" +#include "RenderState.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + +/// +/// Canvas也可以称为render texture,自身也可以作为texture渲染。 +/// +class Canvas ASURA_FINAL + : public Scripting::Portable +{ +public: + + Canvas(); + + ~Canvas(); + + /// + /// 设置render texture的大小 + /// + void SetSize(uint w, uint h) ASURA_THROW(Exception); + + void Clear(const Color& col = Color::Black) override; +/* + void Clear(const Math::Recti& quad, const Color& col = Color::Black) override; +*/ + void Render(const RenderTarget* rt, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); + + void Render(const RenderTarget* rt, const Math::Rectf& quad, const Math::Vector2i& pos, const Math::Vector2i& scale, const Math::Vector2i& center, float rot); + + void Draw(const Drawable* texture, const RenderState& state); + + void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state); + +private: + + GLuint m_FBO; + + GLuint m_TexID; + + uint m_Width, m_Height; + +luaxport: + + LUAX_DECL_FACTORY(Canvas, RenderTarget); + + LUAX_DECL_METHOD(_SetSize); + LUAX_DECL_METHOD(_Bind); + LUAX_DECL_METHOD(_Unbind); + +}; + +/// +/// Canvas别名为RenderTexture +/// +typedef Canvas RenderTexture; + +} // Graphics +} // AsuraEngine + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Color.cpp b/source/modules/asura-core/Graphics/Color.cpp new file mode 100644 index 0000000..5a66291 --- /dev/null +++ b/source/modules/asura-core/Graphics/Color.cpp @@ -0,0 +1,58 @@ +#include "Color.h" +#include "Color32.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +Color::Color() +{ + r = g = b = a = 0; +} + +Color::Color(const Color& c) +{ + r = c.r; + g = c.g; + b = c.b; + a = c.a; +} + +Color::Color(float r, float g, float b, float a) +{ + this->r = r; + this->g = g; + this->b = b; + this->a = a; +} + +Color::Color(const Color32& c) +{ + r = c.r / 255.f; + g = c.g / 255.f; + b = c.b / 255.f; + a = c.a / 255.f; +} + +Color::~Color() +{ +} + +void Color::Set(float r, float g, float b, float a) +{ + this->r = r; + this->g = g; + this->b = b; + this->a = a; +} + +//Color Color::operator *(const Color& c) +//{ +// r *= c.r; +// g *= c.g; +// b *= c.b; +// a *= c.a; + +//} + +namespace_end +namespace_end diff --git a/source/modules/asura-core/Graphics/Color.h b/source/modules/asura-core/Graphics/Color.h new file mode 100644 index 0000000..a16f17d --- /dev/null +++ b/source/modules/asura-core/Graphics/Color.h @@ -0,0 +1,75 @@ +#ifndef _ASURA_ENGINE_COLOR_H_ +#define _ASURA_ENGINE_COLOR_H_ + +#include +#include + +#include "../CoreConfig.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +class Color32; + +/// +/// 规范化颜色,相比Color32有更大的操作性。 +/// +class Color ASURA_FINAL + : public Scripting::Portable +{ +public: + + static Color Black; + static Color White; + static Color Red; + static Color Green; + static Color Blue; + + Color(); + + Color(const Color& c); + + Color(float r, float g, float b, float a); + + Color(const Color32& c); + + ~Color(); + + Color operator *(const Color& c); + + void Set(float r, float g, float b, float a); + + GET_SET(float, Red, r); + GET_SET(float, Green, g); + GET_SET(float, Blue, b); + GET_SET(float, Alpha, a); + + float r, g, b, a; + +luaxport: + + LUAX_DECL_FACTORY(Color); + + LUAX_DECL_METHOD(_ToColor32); + LUAX_DECL_METHOD(_SetColor); + LUAX_DECL_METHOD(_GetColor); + LUAX_DECL_METHOD(_GetR); + LUAX_DECL_METHOD(_GetG); + LUAX_DECL_METHOD(_GetB); + LUAX_DECL_METHOD(_GetA); + + // 元方法 + LUAX_DECL_METHOD(___eq); // __eq + LUAX_DECL_METHOD(___add); // __add + LUAX_DECL_METHOD(___sub); // __sub + LUAX_DECL_METHOD(___mul); // __mul + LUAX_DECL_METHOD(___div); // __div + +}; + +namespace_end +namespace_end + +namespace AEGraphics = AsuraEngine::Graphics; + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Color32.cpp b/source/modules/asura-core/Graphics/Color32.cpp new file mode 100644 index 0000000..f1f0b74 --- /dev/null +++ b/source/modules/asura-core/Graphics/Color32.cpp @@ -0,0 +1,53 @@ +#include "Color.h" +#include "Color32.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +#if ASURA_LITTLE_ENDIAN +// 小端,低字节的Alpha存放在高地址 +const uint32 Color32::RMASK = 0x000000ff; +const uint32 Color32::GMASK = 0x0000ff00; +const uint32 Color32::BMASK = 0x00ff0000; +const uint32 Color32::AMASK = 0xff000000; +#endif + +Color32::Color32() +{ + r = g = b = a = 0; +} + +Color32::Color32(const Color32& c) +{ + r = c.r; + g = c.g; + b = c.b; + a = c.a; +} + +Color32::Color32(const Color& c) +{ + r = 255.f * c.r; + g = 255.f * c.g; + b = 255.f * c.b; + a = 255.f * c.a; +} + +Color32::Color32(byte r, byte g, byte b, byte a) +{ + this->r = r; + this->g = g; + this->b = b; + this->a = a; +} + +void Color32::Set(const Color32& c32) +{ + r = c32.r; + g = c32.g; + b = c32.b; + a = c32.a; +} + +namespace_end +namespace_end \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Color32.h b/source/modules/asura-core/Graphics/Color32.h new file mode 100644 index 0000000..aa445fe --- /dev/null +++ b/source/modules/asura-core/Graphics/Color32.h @@ -0,0 +1,58 @@ +#ifndef _ASURA_ENGINE_COLOR32_H__ +#define _ASURA_ENGINE_COLOR32_H__ + +#include +#include + +#include "../CoreConfig.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +class Color; + +/// +/// 32bits颜色 +/// +class Color32 ASURA_FINAL + : public Scripting::Portable +{ +public: + + static const uint32 RMASK; + static const uint32 GMASK; + static const uint32 BMASK; + static const uint32 AMASK; + + Color32(); + + ~Color32(); + + Color32(const Color32& c); + + Color32(const Color& c); + + Color32(byte r, byte g, byte b, byte a); + + void Set(const Color32& c32); + + byte r, g, b, a; + +luaxport: + + LUAX_DECL_FACTORY(Color32); + + LUAX_DECL_METHOD(_ToColor); + LUAX_DECL_METHOD(_SetColor); + LUAX_DECL_METHOD(_GetColor); + LUAX_DECL_METHOD(_GetRed); + LUAX_DECL_METHOD(_GetGreen); + LUAX_DECL_METHOD(_GetBlue); + LUAX_DECL_METHOD(_GetAlpha); + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/ColorPalette.h b/source/modules/asura-core/Graphics/ColorPalette.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/Graphics/DrawInfo.cpp b/source/modules/asura-core/Graphics/DrawInfo.cpp new file mode 100644 index 0000000..c7a6912 --- /dev/null +++ b/source/modules/asura-core/Graphics/DrawInfo.cpp @@ -0,0 +1,10 @@ +#include "DrawInfo.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + + +namespace_end +namespace_end diff --git a/source/modules/asura-core/Graphics/DrawInfo.h b/source/modules/asura-core/Graphics/DrawInfo.h new file mode 100644 index 0000000..f0e375b --- /dev/null +++ b/source/modules/asura-core/Graphics/DrawInfo.h @@ -0,0 +1,18 @@ +#ifndef _ASURA_ENGINE_DRAWINFO_H_ +#define _ASURA_ENGINE_DRAWINFO_H_ + +#include + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +struct DrawInfo +{ + +}; + + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/GPUBuffer.cpp b/source/modules/asura-core/Graphics/GPUBuffer.cpp new file mode 100644 index 0000000..f28b914 --- /dev/null +++ b/source/modules/asura-core/Graphics/GPUBuffer.cpp @@ -0,0 +1,151 @@ +#include "GPUBuffer.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +GPUBuffer::GPUBuffer(BufferType type, BufferUsage usage, BufferDataType dataType, size_t size) + : m_Target(GL_ZERO) + , m_Buffer(GL_ZERO) + , m_Size(0) +#if ASURA_DEBUG + , m_Data(nullptr) +#endif +{ + m_Target = ConvertBufferType(type); + m_Usage = ConvertBufferUsage(usage); + m_DataType = ConvertBufferDataType(dataType); + m_Size = size; +} + +GPUBuffer::~GPUBuffer() +{ +#if ASURA_DEBUG + if (m_Data) + free(m_Data); +#endif + glDeleteBuffers(1, &m_Buffer); +} + +GLenum GPUBuffer::ConvertBufferType(BufferType type) +{ + switch (type) + { + case BUFFER_TYPE_VERTEX: + return GL_ARRAY_BUFFER; + case BUFFER_TYPE_INDEX: + return GL_ELEMENT_ARRAY_BUFFER; + } +} + +GLenum GPUBuffer::ConvertBufferUsage(BufferUsage usage) +{ + switch (usage) + { + case BUFFER_USAGE_STREAM: + return GL_STREAM_DRAW; + case BUFFER_USAGE_DYNAMIC: + return GL_DYNAMIC_DRAW; + case BUFFER_USAGE_STATIC: + return GL_STATIC_DRAW; + } +} + +GLenum GPUBuffer::ConvertBufferDataType(BufferDataType type) +{ + switch (type) + { + case BUFFER_DATA_TYPE_INT: + return GL_INT; + case BUFFER_DATA_TYPE_FLOAT: + return GL_FLOAT; + case BUFFER_DATA_TYPE_UNSIGNED_BYTE: + return GL_UNSIGNED_BYTE; + } +} + +bool GPUBuffer::Fill(const void * data, size_t size, uint offset) +{ + if (data == nullptr) + return false; + if (m_Buffer == 0) + { + g_Device.WipeError(); + glGenBuffers(1, &m_Buffer); + if (m_Buffer == 0) + throw Exception("OpenGL glGenBuffers failed."); + glBindBuffer(m_Target, m_Buffer); + glBufferData(m_Target, m_Size, NULL, m_Usage); + if (g_Device.HasError()) + { + glBindBuffer(m_Target, 0); + throw Exception("OpenGL glBufferData failed. Errorcode=%d.", g_Device.GetError()); + } +#if ASURA_DEBUG + m_Data = (byte*)malloc(size); + memset(m_Data, 0, size); +#endif + } + else + glBindBuffer(m_Target, m_Buffer); + glBufferSubData(m_Target, offset, size, data); + if (g_Device.HasError()) + { + glBindBuffer(m_Target, 0); + throw Exception("OpenGL glBufferSubData failed. Errorcode=%d.", g_Device.GetError()); + } + glBindBuffer(m_Target, 0); +#if ASURA_DEBUG + memcpy(m_Data + offset, data, size); +#endif + return true; +} + +void GPUBuffer::Bind() +{ + glBindBuffer(m_Target, m_Buffer); +} + +void GPUBuffer::UnBind() +{ + glBindBuffer(m_Target, 0); +} + +uint GPUBuffer::GetBufferSize() +{ + return m_Size; +} + +GLenum GPUBuffer::GetDataType() +{ + return m_DataType; +} + +size_t GPUBuffer::GetDataTypeSize() +{ + //https://blog.csdn.net/nklinux/article/details/16919017 + switch (m_DataType) + { + case GL_UNSIGNED_BYTE: + return sizeof(GLbyte); + case GL_FLOAT : + return sizeof(GLfloat); + case GL_INT: + return sizeof(GLint); + } +} + +size_t GPUBuffer::GetDataTypeSize(GLenum datatype) +{ + switch (datatype) + { + case GL_UNSIGNED_BYTE: + return sizeof(GLbyte); + case GL_FLOAT: + return sizeof(GLfloat); + case GL_INT: + return sizeof(GLint); + } +} + +namespace_end +namespace_end \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/GPUBuffer.h b/source/modules/asura-core/Graphics/GPUBuffer.h new file mode 100644 index 0000000..bb40055 --- /dev/null +++ b/source/modules/asura-core/Graphics/GPUBuffer.h @@ -0,0 +1,95 @@ +#ifndef _ASURA_GPU_BUFFER_H_ +#define _ASURA_GPU_BUFFER_H_ + +#include +#include +#include + +#include "GfxDevice.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +enum BufferType +{ + BUFFER_TYPE_VERTEX, ///< 顶点缓冲,保存position\tangent\normal\color\texcoord(n) + BUFFER_TYPE_INDEX, ///< 索引缓冲 +}; + +enum BufferUsage +{ + BUFFER_USAGE_STREAM, ///< 修改一次,使用次数低 + BUFFER_USAGE_DYNAMIC, ///< 修改一次,经常使用 + BUFFER_USAGE_STATIC, ///< 经常修改和使用 +}; + +enum BufferDataType +{ + BUFFER_DATA_TYPE_INT, + BUFFER_DATA_TYPE_FLOAT, + BUFFER_DATA_TYPE_UNSIGNED_BYTE, +}; + +/// +/// VRAM缓冲,分顶点缓冲vbo和索引缓冲ebo两种,避免每次都从内存向显存上传数据。在framework的renderers中 +/// 构建。 +/// +ASURA_ABSTRACT class GPUBuffer +{ +public: + + GPUBuffer(BufferType type, BufferUsage usage, BufferDataType datatype, size_t size); + virtual ~GPUBuffer(); + + static size_t GetDataTypeSize(GLenum datatype); + + bool Fill(const void* data, size_t size, uint offset = 0) ASURA_THROW(Exception); + + void Bind(); + void UnBind(); + + uint GetBufferSize(); + uint GetBufferCount(); + GLenum GetDataType(); + size_t GetDataTypeSize(); + +private: + + GLenum ConvertBufferType(BufferType type); + GLenum ConvertBufferUsage(BufferUsage type); + GLenum ConvertBufferDataType(BufferDataType type); + + GLenum m_Target; + GLuint m_Buffer; + + /// opengl的显存缓冲并没有对数据类型的要求,只在glVertexAttribPointer时会指定,并在drawcall 时根据给定 + /// 的数据起始地址和类型从buffer中取各类顶点数据,所以不同的数据类型可以保存在一个buffer中。但是为了保持 + /// 接口的简洁,这里在初始化buffer时指明保存的数据类型,并在整个周期内保持数据类型的一致,所以不同的数据 + /// 类型分属不同的buffer。 + + GLenum m_DataType; + GLuint m_Usage; + uint m_Size; + +#if ASURA_DEBUG + byte* m_Data; +#endif + +luaxport: + + LUAX_DECL_ABSTRACT_FACTORY(GPUBuffer); + + LUAX_DECL_ENUM(BufferType, 1); + LUAX_DECL_ENUM(BufferUsage, 1); + LUAX_DECL_ENUM(BufferDataType, 2); + + LUAX_DECL_METHOD(_Fill); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_GetCount); + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/GfxDevice.cpp b/source/modules/asura-core/Graphics/GfxDevice.cpp new file mode 100644 index 0000000..ef324e3 --- /dev/null +++ b/source/modules/asura-core/Graphics/GfxDevice.cpp @@ -0,0 +1,208 @@ +#include + +#include "../CoreConfig.h" + +#include "GfxDevice.h" +#include "Shader.h" +#include "MatrixStack.h" +#include "Color.h" + +using namespace AEMath; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +#if ASURA_DEBUG +static bool instantiated = false; +#endif + +GfxDevice g_Device; + +GfxDevice::GfxDevice() +{ +#if ASURA_DEBUG + ASSERT(!instantiated); + instantiated = true; +#endif +} + +GfxDevice::~GfxDevice() +{ +} + +GfxDevice& GfxDevice::Get() +{ + return g_Device; +} + +static bool inited = false; + +bool GfxDevice::Init(const AEMath::Recti& view) +{ + bool loaded = false; +#if ASURA_OPENGL_LOADER & ASURA_OPENGL_GLAD + if (!loaded) + loaded = gladLoadGL(); +#endif + if (!loaded) + return false; + SetViewport(view); + + inited = true; + return true; +} + +bool GfxDevice::Inited() +{ + return inited; +} + +void GfxDevice::WipeError() +{ + while (glGetError() != GL_NO_ERROR); +} + +bool GfxDevice::HasError() +{ + return glGetError() != GL_NO_ERROR; +} + +GLenum GfxDevice::GetError() +{ + return glGetError(); +} + +void GfxDevice::SetDrawColor(float r, float g, float b, float a) +{ + state.drawColor.Set(r, g, b, a); +} + +Color& GfxDevice::GetDrawColor() +{ + return state.drawColor; +} + +Canvas* GfxDevice::GetActiveCanvas() const +{ + return state.canvas; +} + +void GfxDevice::SetActiveCanvas(Canvas* canvas) +{ + state.canvas = canvas; +} + +void GfxDevice::SetViewport(const Recti v) +{ + state.viewport = v; + glViewport(v.x, v.y, v.w, v.h); +} + +const Recti& GfxDevice::GetViewport() +{ + return state.viewport; +} + +void GfxDevice::SetActiveShader(Shader* shader) +{ + if (state.shader == shader) + return; + if (state.shader) + state.shader->OnDisable(); + state.shader = shader; + if (shader) + { + GLint program = shader->GetGLProgram(); + glUseProgram(program); +#if ASURA_GL_PROFILE + ++stats.shaderSwitch; +#endif + shader->OnEnable(); + } +} + +Shader* GfxDevice::GetActiveShader() const +{ + return state.shader; +} + +void GfxDevice::DrawArrays(GLenum mode, GLint first, GLsizei count) +{ + glDrawArrays(mode, first, count); +#if ASURA_GL_PROFILE + ++stats.drawCall; +#endif + if (state.shader) + state.shader->OnUsed(); +} + +void GfxDevice::SetMatrixMode (MatrixMode mode) +{ + state.matrixMode = mode; +} + +MatrixMode GfxDevice::GetMatrixMode () +{ + return state.matrixMode; +} + +void GfxDevice::PushMatrix () +{ + state.matrix[state.matrixMode].Push (); +} + +void GfxDevice::PopMatrix () +{ + state.matrix[state.matrixMode].Pop(); +} + +void GfxDevice::LoadIdentity() +{ + state.matrix[state.matrixMode].LoadIdentity(); +} + +void GfxDevice::Rotate (float angle) +{ + state.matrix[state.matrixMode].Rotate(angle); +} + +void GfxDevice::Translate (float x, float y) +{ + state.matrix[state.matrixMode].Translate(x, y); +} + +void GfxDevice::Scale (float x, float y) +{ + state.matrix[state.matrixMode].Scale(x, y); +} + +void GfxDevice::Ortho(float l, float r, float b, float t, float n, float f) +{ + state.matrix[state.matrixMode].Ortho(l, r, b, t, n, f); +} + +AEMath::Matrix44& GfxDevice::GetMatrix(MatrixMode mode) +{ + return state.matrix[mode].GetTop(); +} + +AEMath::Matrix44 GfxDevice::GetMVPMatrix() +{ + return state.matrix[MATRIX_MODE_PROJECTION].GetTop() + * state.matrix[MATRIX_MODE_VIEW].GetTop() + * state.matrix[MATRIX_MODE_MODEL].GetTop(); +} + +uint GfxDevice::GetMatrixDepth() +{ + return state.matrix[state.matrixMode].GetCapacity(); +} + +uint GfxDevice::GetMatrixIndex() +{ + return state.matrix[state.matrixMode].GetTopIndex(); +} + + +namespace_end +namespace_end \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/GfxDevice.h b/source/modules/asura-core/Graphics/GfxDevice.h new file mode 100644 index 0000000..1f50b57 --- /dev/null +++ b/source/modules/asura-core/Graphics/GfxDevice.h @@ -0,0 +1,139 @@ +#ifndef _ASURA_ENGINE_GFX_DEVICE_H_ +#define _ASURA_ENGINE_GFX_DEVICE_H_ + +#include + +#include + +#include +#include +#include +#include + +#include "Color.h" +#include "MatrixStack.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +class Profiler; +class Shader; +class GPUBuffer; +class Canvas; + +enum MatrixMode +{ + MATRIX_MODE_PROJECTION = 0, + MATRIX_MODE_MODEL = 1, + MATRIX_MODE_VIEW = 2, +}; + +enum GLParams +{ + GL_PARAM_MAX_TEXTURE_UNIT = 1, +}; + +class GfxDevice : public AEScripting::Portable +{ +public: + + GfxDevice(); + ~GfxDevice(); + + static GfxDevice& Get(); + + int GetParam(GLParams param); + + bool Init(const AEMath::Recti& viewport); + bool Inited(); + + void SetViewport(const AEMath::Recti viewport); + + const AEMath::Recti& GetViewport(); + + void SetMatrixMode(MatrixMode mode); + MatrixMode GetMatrixMode(); + + void PushMatrix(); + void PopMatrix(); + + void LoadIdentity(); + void Rotate(float angle); + void Translate(float x, float y); + void Scale(float x, float y); + void Ortho(float l, float r, float b, float t, float n, float f); + + uint GetMatrixDepth(); + uint GetMatrixIndex(); + + AEMath::Matrix44& GetMatrix(MatrixMode mode); + AEMath::Matrix44 GetMVPMatrix(); + + void SetDrawColor(float r, float g, float b, float a); + Color& GetDrawColor(); + + void SetActiveCanvas(Canvas* = NULL); + Canvas* GetActiveCanvas() const; + + void SetActiveShader(Shader* = NULL); + Shader* GetActiveShader() const; + + void DrawArrays(GLenum mode, GLint first, GLsizei count); + + void WipeError(); + bool HasError(); + GLenum GetError(); + +private: + + friend class Profiler; + + struct + { + AEMath::Recti viewport; ///< 当前的视区,在切换HDC或者本窗口大小改变或者部分刷新时变动 + MatrixStack matrix[3]; ///< model, view, projection矩阵 + MatrixMode matrixMode; ///< 当前操作的矩阵 + Color drawColor; ///< 绘制的颜色 + Canvas* canvas; ///< 当前canvas + Shader* shader; ///< 当前使用的shader + } state; + +#if ASURA_GL_PROFILE + struct + { + uint drawCall; ///< 统计drawcall + uint canvasSwitch; ///< 切换texture的次数 + uint shaderSwitch; ///< 切换shader的次数 + } stats; +#endif + +luaxport: + + LUAX_DECL_SINGLETON(GfxDevice); + + LUAX_DECL_ENUM(MatrixMode, 1); + LUAX_DECL_ENUM(GLParams, 1); + + LUAX_DECL_METHOD(_SetMatrixMode); + LUAX_DECL_METHOD(_GetMatrixMode); + LUAX_DECL_METHOD(_PushMatrix); + LUAX_DECL_METHOD(_PopMatrix); + LUAX_DECL_METHOD(_LoadIdentity); + LUAX_DECL_METHOD(_Rotate); + LUAX_DECL_METHOD(_Translate); + LUAX_DECL_METHOD(_Scale); + LUAX_DECL_METHOD(_Ortho); + LUAX_DECL_METHOD(_GetMatrixDepth); + LUAX_DECL_METHOD(_GetMatrixIndex); + LUAX_DECL_METHOD(_UseShader); + LUAX_DECL_METHOD(_UnuseShader); + +}; + +// 全局 GfxDevice 对象 +extern GfxDevice g_Device; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Image.cpp b/source/modules/asura-core/Graphics/Image.cpp new file mode 100644 index 0000000..d2b2ec9 --- /dev/null +++ b/source/modules/asura-core/Graphics/Image.cpp @@ -0,0 +1,103 @@ +#include + +#include "../CoreConfig.h" + +#include "Shader.h" +#include "Image.h" +#include "GfxDevice.h" + +using namespace AEIO; +using namespace AEImage; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +Image::Image() + : m_Width(0) + , m_Height(0) +{ +} + +Image::~Image() +{ +} + +bool Image::Load(ImageData* imgData) +{ + if (!imgData) return false; + + if (m_TexID == 0) + { + glGenTextures(1, &m_TexID); + if (m_TexID == 0) + throw Exception("OpenGL glGenTextures failed."); + } + + glBindTexture(GL_TEXTURE_2D, m_TexID); + imgData->Lock(); + int width = imgData->width; + int height = imgData->height; + TextureFormat tf = ConvertColorFormat(imgData->format); + glTexImage2D( + GL_TEXTURE_2D + , 0 + , tf.internalformat + , width, height + , 0 + , tf.externalformat + , tf.type + , imgData->pixels + ); + + m_Width = imgData->width; + m_Height = imgData->height; + imgData->Unlock(); + GLenum err = glGetError(); + if (err != GL_NO_ERROR) + throw Exception("OpenGL glTexImage2D cause error, error code=%d", err); + glBindTexture(GL_TEXTURE_2D, 0); + + return true; +} + +bool Image::Load(ImageData* imgData, const AEMath::Vector2i& pos) +{ + if (!imgData) return false; + + glBindTexture(GL_TEXTURE_2D, m_TexID); + imgData->Lock(); + int width = imgData->width; + int height = imgData->height; + TextureFormat tf = ConvertColorFormat(imgData->format); + glTexSubImage2D( + GL_TEXTURE_2D + , 0 + , pos.x + , pos.y + , imgData->width + , imgData->height + , tf.externalformat + , tf.type + , imgData->pixels + ); + imgData->Unlock(); + GLenum err = glGetError(); + if (err != GL_NO_ERROR) + throw Exception("OpenGL glTexSubImage2D cause error, error code=%d", err); + glBindTexture(GL_TEXTURE_2D, 0); + + return true; +} + +uint32 Image::GetWidth() +{ + return m_Width; +} + +uint32 Image::GetHeight() +{ + return m_Height; +} + +namespace_end +namespace_end \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Image.h b/source/modules/asura-core/Graphics/Image.h new file mode 100644 index 0000000..5cbfe23 --- /dev/null +++ b/source/modules/asura-core/Graphics/Image.h @@ -0,0 +1,63 @@ +#ifndef _ASURA_ENGINE_IMAGE_H_ +#define _ASURA_ENGINE_IMAGE_H_ + +// asura modules +#include +#include +#include +#include +#include +#include + +// module +#include "../Image/ImageData.h" + +// folder +#include "Color.h" +#include "Color32.h" +#include "RenderState.h" +#include "GPUBuffer.h" +#include "Texture.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +class Image ASURA_FINAL : public AEScripting::Portable +{ +public: + + Image(); + ~Image(); + + bool Load(AEImage::ImageData* decodeData); + bool Load(AEImage::ImageData* decodeData, const AEMath::Vector2i& pos); + + uint GetWidth(); + uint GetHeight(); + + GPUBuffer* GenGPUBuffer(); + +private: + + uint32 m_Width, m_Height; + +luaxport: + + LUAX_DECL_FACTORY(Image, Texture); + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Load); + LUAX_DECL_METHOD(_GetWidth); + LUAX_DECL_METHOD(_GetHeight); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_GetPixel); + LUAX_DECL_METHOD(_Render); + +}; + +namespace_end +namespace_end + +namespace AEGraphics = AsuraEngine::Graphics; + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/IndexBuffer.cpp b/source/modules/asura-core/Graphics/IndexBuffer.cpp new file mode 100644 index 0000000..bb3eea7 --- /dev/null +++ b/source/modules/asura-core/Graphics/IndexBuffer.cpp @@ -0,0 +1,17 @@ +#include "IndexBuffer.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + +IndexBuffer::IndexBuffer(BufferUsage usage, BufferDataType datatype, size_t size) + : GPUBuffer(BUFFER_TYPE_INDEX, usage, datatype, size) +{ +} + +IndexBuffer::~IndexBuffer() +{ +} + +namespace_end +namespace_end diff --git a/source/modules/asura-core/Graphics/IndexBuffer.h b/source/modules/asura-core/Graphics/IndexBuffer.h new file mode 100644 index 0000000..73a6f9b --- /dev/null +++ b/source/modules/asura-core/Graphics/IndexBuffer.h @@ -0,0 +1,34 @@ +#ifndef _ASURA_INDEX_BUFFER_H_ +#define _ASURA_INDEX_BUFFER_H_ + +#include + +#include "GPUBuffer.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// 顶点数据 +/// +class IndexBuffer ASURA_FINAL + : public AEScripting::Portable + , public GPUBuffer +{ +public: + + IndexBuffer(BufferUsage usage, BufferDataType datatype, size_t size); + ~IndexBuffer(); + +luaxport: + + LUAX_DECL_FACTORY(IndexBuffer); + + LUAX_DECL_METHOD(_New); + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/MatrixStack.cpp b/source/modules/asura-core/Graphics/MatrixStack.cpp new file mode 100644 index 0000000..987d29c --- /dev/null +++ b/source/modules/asura-core/Graphics/MatrixStack.cpp @@ -0,0 +1,75 @@ +#include "MatrixStack.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +MatrixStack::MatrixStack() + : top(0) +{ + // 栈的最下面初始就是栈顶,并用此保证栈永远非空(即可以取值) + m_Stack[top].SetIdentity(); +} + +MatrixStack::~MatrixStack() +{ +} + +void MatrixStack::LoadIdentity() +{ + m_Stack[top].SetIdentity(); +} + +bool MatrixStack::Push() +{ + if (top == ASURA_MAX_MATRIX_STACK_DEPTH - 1) + return false; + ++top; + m_Stack[top] = m_Stack[top - 1]; + return true; +} + +bool MatrixStack::Pop() +{ + if (top == 0) + return false; + --top; + return true; +} + +AEMath::Matrix44& MatrixStack::GetTop() +{ + return m_Stack[top]; +} + +uint MatrixStack::GetTopIndex() +{ + return top; +} + +uint MatrixStack::GetCapacity() +{ + return ASURA_MAX_MATRIX_STACK_DEPTH; +} + +void MatrixStack::Ortho(float left, float right, float bottom, float top, float near, float far) +{ + m_Stack[this->top].Ortho(left, right, bottom, top, near, far); +} + +void MatrixStack::Rotate(float angle) +{ + m_Stack[top].Rotate(angle); +} + +void MatrixStack::Translate(float x, float y) +{ + m_Stack[top].Translate(x, y); +} + +void MatrixStack::Scale(float x, float y) +{ + m_Stack[top].Scale(x, y); +} + +namespace_end +namespace_end \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/MatrixStack.h b/source/modules/asura-core/Graphics/MatrixStack.h new file mode 100644 index 0000000..867011e --- /dev/null +++ b/source/modules/asura-core/Graphics/MatrixStack.h @@ -0,0 +1,58 @@ +#ifndef _ASURA_MATRIX_STACK_H_ +#define _ASURA_MATRIX_STACK_H_ + +#include +#include +#include + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// 栈的矩阵深度。 +/// +#define ASURA_MAX_MATRIX_STACK_DEPTH 32 // 2KB + +/// +/// 保存栈状态,用来恢复之前的状态。栈中的一个矩阵stack[i]的值是stack[0]*..*stack[i-1] +/// 的值,并附加一系列transform。 +/// +/// TODO: template MatrixStack +/// +class MatrixStack +{ +public: + + MatrixStack(); + ~MatrixStack(); + + void LoadIdentity(); + bool Push(); + bool Pop(); + + AEMath::Matrix44& GetTop(); + void GetTop(ASURA_OUT AEMath::Matrix44& mat44); + + void LoadMatrix(const AEMath::Matrix44& mat44); + void MultMatrix(const AEMath::Matrix44& mat44); + + void Rotate(float angle); + void Translate(float x, float y); + void Scale(float x, float y); + + void Ortho(float l, float r, float b, float t, float n, float f); + + uint GetTopIndex(); + uint GetCapacity(); + +private: + + AEMath::Matrix44 m_Stack[ASURA_MAX_MATRIX_STACK_DEPTH]; + uint8 top; + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Mesh2D.cpp b/source/modules/asura-core/Graphics/Mesh2D.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/Graphics/Mesh2D.h b/source/modules/asura-core/Graphics/Mesh2D.h new file mode 100644 index 0000000..1546765 --- /dev/null +++ b/source/modules/asura-core/Graphics/Mesh2D.h @@ -0,0 +1,52 @@ +#ifndef _ASURA_ENGINE_MESH2D_H__ +#define _ASURA_ENGINE_MESH2D_H__ + +// cpp +#include + +// asura modules +#include +#include + +// module +#include "../Mesh/Mesh2dData.h" + +// folder +#include "Color.h" +#include "VertexBuffer.h" +#include "IndexBuffer.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// 2D mesh,用于做一些顶点动画。 +/// https://en.wikipedia.org/wiki/Polygon_mesh +/// +class Mesh2D ASURA_FINAL + : public Scripting::Portable +{ +public: + + Mesh2D(); + ~Mesh2D(); + + bool Load(AEMesh::Mesh2DData* data); + +private: + + VertexBuffer* m_VBO; ///< vertex buffer + IndexBuffer* m_IBO; ///< index buffer + +luaxport: + + LUAX_DECL_FACTORY(Mesh2D); + + LUAX_DECL_METHOD(_SetVertex); + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Quad.cpp b/source/modules/asura-core/Graphics/Quad.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/Graphics/Quad.h b/source/modules/asura-core/Graphics/Quad.h new file mode 100644 index 0000000..b7dd3d9 --- /dev/null +++ b/source/modules/asura-core/Graphics/Quad.h @@ -0,0 +1 @@ +// Quad和rect的区别在于,rect是的边偏向于轴,quad不一定。 diff --git a/source/modules/asura-core/Graphics/RenderState.h b/source/modules/asura-core/Graphics/RenderState.h new file mode 100644 index 0000000..5dcf12d --- /dev/null +++ b/source/modules/asura-core/Graphics/RenderState.h @@ -0,0 +1,47 @@ +#ifndef _ASURA_ENGINE_RENDER_STATE_H_ +#define _ASURA_ENGINE_RENDER_STATE_H_ + +#include +#include + +#include "BlendMode.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +class Shader; + +/// +/// 渲染当前纹理的方式 +/// +struct RenderState ASURA_FINAL +{ + /// + /// 默认的render state + /// + static RenderState Default; + + RenderState(); + ~RenderState(); + + /// + /// 位置、缩放、中心位置和旋转 + /// + Math::Transform transform; + + /// + /// 着色器 + /// + Shader* shader; + + /// + /// 混合方式 + /// + BlendMode blendMode; + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/RenderTarget.cpp b/source/modules/asura-core/Graphics/RenderTarget.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/Graphics/RenderTarget.h b/source/modules/asura-core/Graphics/RenderTarget.h new file mode 100644 index 0000000..bcd7276 --- /dev/null +++ b/source/modules/asura-core/Graphics/RenderTarget.h @@ -0,0 +1,52 @@ +#ifndef _ASURA_ENGINE_RENDERTARGET_H_ +#define _ASURA_ENGINE_RENDERTARGET_H_ + +#include +#include +#include + +#include "Texture.h" +#include "Color.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// 可被作为渲染目标的类,派生类有 +/// Canvas(RenderTexture) +/// Window(RenderWindow) +/// +class RenderTarget : public AEScripting::Object +{ +public: + + RenderTarget() {}; + + virtual ~RenderTarget() {}; + + /// + /// 用颜色col清空整个RT + /// + virtual void Clear(const Color& col = Color::Black) = 0; + + /// + /// 用颜色col清空部分RT + /// + virtual void Clear(const Math::Recti& quad, const Color& col = Color::Black) = 0; + + /// + /// 绘制texture到本RT上 + /// + virtual void Draw(const Drawable* texture, const RenderState& state) = 0; + + /// + /// 绘制一部分texture到本RT上 + /// + virtual void Draw(const Drawable* texture, const Math::Recti& quad, const RenderState& state) = 0; + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Shader.cpp b/source/modules/asura-core/Graphics/Shader.cpp new file mode 100644 index 0000000..30e0161 --- /dev/null +++ b/source/modules/asura-core/Graphics/Shader.cpp @@ -0,0 +1,282 @@ +#include + +#include "GfxDevice.h" +#include "Shader.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +// texture unit编号 +static uint8 texUnit = 0; + +Shader::Shader() +{ +} + +Shader::~Shader() +{ + if(m_VertShader) glDeleteShader(m_VertShader); + if(m_FragShader) glDeleteShader(m_FragShader); + if(m_Program) glDeleteProgram(m_Program); +} + +void Shader::SetActive(Shader* shader) +{ + g_Device.SetActiveShader(shader); +} + +Shader* Shader::GetActive() +{ + return g_Device.GetActiveShader(); +} + +bool Shader::Load(const string& vert, const string& frag) +{ + string warnning = ""; + + if (!m_Program) + { + m_Program = glCreateProgram(); + if (!m_Program) + throw Exception("Cannot create OpenGL shader program."); + } + + if (!CompileVertexShader(vert, warnning)) + { + throw Exception("Compile vertex shader failed:%s", warnning); + } + + if (!CompileFragementShader(frag, warnning)) + { + throw Exception("Compile fragment shader failed:%s", warnning); + } + + glAttachShader(m_Program, m_VertShader); + glAttachShader(m_Program, m_FragShader); + + glLinkProgram(m_Program); + GLint success; + glGetProgramiv(m_Program, GL_LINK_STATUS, &success); + if (success == GL_FALSE) + { + warnning = GetProgramWarnings(); + throw Exception("Link shader program failed:\n%s", warnning.c_str()); + } + + return true; +} + +bool Shader::CompileVertexShader(const string& vert, string& outError) +{ + if (!m_VertShader) + { + m_VertShader = glCreateShader(GL_VERTEX_SHADER); + if (!m_VertShader) + { + outError = "Cannot create OpenGL Vertex shader."; + return false; + } + } + + const GLchar* source = vert.c_str(); + GLint success; + + glShaderSource(m_VertShader, 1, &source, NULL); + glCompileShader(m_VertShader); + glGetShaderiv(m_VertShader, GL_COMPILE_STATUS, &success); + if (success == GL_FALSE) + { + outError = GetShaderWarnings(m_VertShader); + return false; + } + + return true; +} + +bool Shader::CompileFragementShader(const string& frag, string& outError) +{ + if (!m_FragShader) + { + m_FragShader = glCreateShader(GL_FRAGMENT_SHADER); + if (!m_FragShader) + { + outError = "Cannot create OpenGL fragment shader."; + return false; + } + } + + const GLchar* source = frag.c_str(); + GLint success; + + source = frag.c_str(); + glShaderSource(m_FragShader, 1, &source, NULL); + glCompileShader(m_FragShader); + glGetShaderiv(m_FragShader, GL_COMPILE_STATUS, &success); + if (success == GL_FALSE) + { + outError = GetShaderWarnings(m_FragShader); + return false; + } + + return true; +} + +void Shader::OnEnable() +{ + texUnit = 0; +} + +void Shader::OnDisable() +{ + texUnit = 0; +} + +void Shader::OnUsed() +{ + texUnit = 0; +} + +uint Shader::GetUniformLocation(const std::string& uniform) +{ + GLint loc = glGetUniformLocation(m_Program, uniform.c_str()); + return loc; +} + +bool Shader::HasUniform(const std::string& uniform) +{ + GLint loc = glGetUniformLocation(m_Program, uniform.c_str()); + return loc != -1; +} + +GLuint Shader::GetGLProgram() +{ + return m_Program; +} + +void Shader::SetUniformFloat(uint loc, float value) +{ + if(g_Device.GetActiveShader() == this) + glUniform1f(loc, value); +} + +bool Shader::SetUniformTexture(uint loc, const Texture& texture) +{ + if (g_Device.GetActiveShader() != this) + return false; + + g_Device.WipeError(); + glActiveTexture(GL_TEXTURE0 + texUnit); + if (g_Device.HasError()) + return false; + GLint tex = texture.GetGLTexture(); + glBindTexture(GL_TEXTURE_2D, tex); + if (g_Device.HasError()) + return false; + glUniform1i(loc, texUnit); + if (g_Device.HasError()) + return false; + ++texUnit; +} + +void Shader::SetUniformVector2(uint loc, const Math::Vector2f& vec2) +{ + if (g_Device.GetActiveShader() == this) + glUniform2f(loc, vec2.x, vec2.y); +} + +void Shader::SetUniformVector3(uint loc, const Math::Vector3f& vec3) +{ + if (g_Device.GetActiveShader() == this) + glUniform3f(loc, vec3.x, vec3.y, vec3.z); +} + +void Shader::SetUniformVector4(uint loc, const Math::Vector4f& vec4) +{ + if (g_Device.GetActiveShader() == this) + glUniform4f(loc, vec4.x, vec4.y, vec4.z, vec4.w); +} + +void Shader::SetUniformMatrix44(uint loc, const Math::Matrix44& mat) +{ + if (g_Device.GetActiveShader() == this) + glUniformMatrix4fv(loc, 1, GL_FALSE, mat.GetElements()); +} + +void Shader::SetUniformColor(uint loc, const Color& color) +{ + if (g_Device.GetActiveShader() == this) + glUniform4f(loc, color.r, color.g, color.b, color.a); +} + +uint Shader::GetGLTextureUnitCount() +{ + GLint maxTextureUnits; + glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &maxTextureUnits); + return (uint)maxTextureUnits; +} + +std::string Shader::GetProgramWarnings() +{ + GLint strsize, nullpos; + glGetProgramiv(m_Program, GL_INFO_LOG_LENGTH, &strsize); + + if (strsize == 0) + return ""; + + char *tempstr = new char[strsize]; + + memset(tempstr, '\0', strsize); + glGetProgramInfoLog(m_Program, strsize, &nullpos, tempstr); + tempstr[nullpos] = '\0'; + + std::string warnings(tempstr); + delete[] tempstr; + + return warnings; +} + +std::string Shader::GetShaderWarnings(GLuint shader) +{ + GLint strsize, nullpos; + glGetShaderiv(shader, GL_INFO_LOG_LENGTH, &strsize); + + if (strsize == 0) + return ""; + + char *tempstr = new char[strsize]; + + memset(tempstr, '\0', strsize); + glGetShaderInfoLog(shader, strsize, &nullpos, tempstr); + tempstr[nullpos] = '\0'; + + std::string warnings(tempstr); + delete[] tempstr; + + return warnings; +} + +void Shader::SetAttribute(int loc, VertexBuffer* vbo, uint offseti, uint stridei, bool normalized) +{ + GLsizei offset = offseti * vbo->GetDataTypeSize(); + GLsizei stride = stridei * vbo->GetDataTypeSize(); + glEnableVertexAttribArray(loc); + vbo->Bind(); + glVertexAttribPointer(loc, 2, vbo->GetDataType(), normalized, stride, (GLvoid*)offset); + vbo->UnBind(); +} + +int Shader::GetAttributeLocation(const std::string& attribute) +{ + int loc = glGetAttribLocation(m_Program, attribute.c_str()); + return loc; +} + +void Shader::DisableAttribute(int loc) +{ + glDisableVertexAttribArray(loc); +} + +namespace_end +namespace_end \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Shader.h b/source/modules/asura-core/Graphics/Shader.h new file mode 100644 index 0000000..c96b99f --- /dev/null +++ b/source/modules/asura-core/Graphics/Shader.h @@ -0,0 +1,117 @@ +#ifndef _ASURA_ENGINE_SHADER_H_ +#define _ASURA_ENGINE_SHADER_H_ + +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "GfxDevice.h" +#include "Color.h" +#include "Texture.h" +#include "VertexBuffer.h" +#include "IndexBuffer.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// 一个shader是一个在材质间共享的程序。Shader本身不保存uniforms和顶点数据,只提供设置 uniforms和use着色 +/// 器的方法。编辑器针对每个shader,会通过shader代码找到声明的uniforms变量,并暴露给framework的material +/// 设置。 +/// +class Shader ASURA_FINAL + : public Scripting::Portable + , public AEIO::Renewable +{ +public: + + Shader(); + + ~Shader(); + + static void SetActive(Shader* shader); + static Shader* GetActive(); + + bool Load(const std::string& vert, const std::string& frag) ASURA_THROW(Exception); + + // 使用SetActive切换shader时调用 + void OnEnable(); + void OnDisable(); + // Draw call之后调用 + void OnUsed(); + + void SetAttribute(int loc, VertexBuffer* vbo, uint offseti = 0, uint stridei = 0, bool normalized = false); + int GetAttributeLocation(const std::string& attribute); + void DisableAttribute(int loc); + + bool HasUniform(const std::string& uniform); + uint GetUniformLocation(const std::string& uniform); + void SetUniformFloat(uint loc, float value); + void SetUniformVector2(uint loc, const Math::Vector2f& vec2); + void SetUniformVector3(uint loc, const Math::Vector3f& vec3); + void SetUniformVector4(uint loc, const Math::Vector4f& vec4); + void SetUniformColor(uint loc, const Color& color); + void SetUniformMatrix44(uint loc, const Math::Matrix44& mat44); + bool SetUniformTexture(uint loc, const Texture& texture); + + float GetUniformFloat(uint loc); + AEMath::Vector2f GetUniformVector2(uint loc); + AEMath::Vector3f GetUniformVector3(uint loc); + AEMath::Vector4f GetUniformVector4s(uint loc); + AEMath::Matrix44 GetUniformMatrix44(uint loc); + + GLuint GetGLProgram(); + + static uint GetGLTextureUnitCount(); + +private: + + bool CompileVertexShader(const std::string& vert, std::string& outError); + bool CompileFragementShader(const std::string& frag, std::string& outError); + + std::string GetProgramWarnings(); + std::string GetShaderWarnings(GLuint shader); + + GLuint m_Program; + GLuint m_VertShader; + GLuint m_FragShader; + +luaxport: + + LUAX_DECL_FACTORY(Shader); + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_Load); + LUAX_DECL_METHOD(_Update); + LUAX_DECL_METHOD(_HasUniform); + LUAX_DECL_METHOD(_GetUniformLocation); + LUAX_DECL_METHOD(_SetUniformFloat); + LUAX_DECL_METHOD(_SetUniformTexture); + LUAX_DECL_METHOD(_SetUniformVector2); + LUAX_DECL_METHOD(_SetUniformVector3); + LUAX_DECL_METHOD(_SetUniformVector4); + LUAX_DECL_METHOD(_SetUniformColor); + + LUAX_DECL_METHOD(_GetAttributeLocation); + LUAX_DECL_METHOD(_SetAttribute); + LUAX_DECL_METHOD(_DisableAttribute); + + LUAX_DECL_METHOD(_SetBuiltInUniforms); + +}; + +typedef Shader GpuProgram; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Shape.cpp b/source/modules/asura-core/Graphics/Shape.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/Graphics/Shape.h b/source/modules/asura-core/Graphics/Shape.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/Graphics/SpriteBatch.cpp b/source/modules/asura-core/Graphics/SpriteBatch.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/Graphics/SpriteBatch.h b/source/modules/asura-core/Graphics/SpriteBatch.h new file mode 100644 index 0000000..a98d1f4 --- /dev/null +++ b/source/modules/asura-core/Graphics/SpriteBatch.h @@ -0,0 +1,34 @@ +#ifndef _ASURA_ENGINE_SPRITE_BATCH_H_ +#define _ASURA_ENGINE_SPRITE_BATCH_H_ + +#include + +#include "GPUBuffer.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// Sprite batch用在批量渲染单个图片的地方,比如粒子系统。 +/// +class SpriteBatch ASURA_FINAL + : public Scripting::Portable +{ +public: + + SpriteBatch(); + + ~SpriteBatch(); + +private: + +luaxport: + + LUAX_DECL_FACTORY(SpriteBatch); + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Texture.cpp b/source/modules/asura-core/Graphics/Texture.cpp new file mode 100644 index 0000000..bae0f7c --- /dev/null +++ b/source/modules/asura-core/Graphics/Texture.cpp @@ -0,0 +1,47 @@ +#include + +#include "Texture.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +Texture::Texture() + : m_TexID(0) +{ +} + +Texture::~Texture() +{ + // 释放纹理资源 + if(m_TexID != 0) + glDeleteTextures(1, &m_TexID); +} + +GLuint Texture::GetGLTexture() const +{ + return m_TexID; +} + +TextureFormat Texture::ConvertColorFormat(const ColorFormat& colorformat) +{ + TextureFormat t; + switch (colorformat) + { + case COLOR_FORMAT_RGBA8: + t.internalformat = GL_RGBA8; // 4*sizeof(byte) ~= 4 bytes + t.externalformat = GL_RGBA; + t.type = GL_UNSIGNED_BYTE; + break; + case COLOR_FORMAT_RGBA32F: + t.internalformat = GL_RGBA32F; // 4*sizeof(float) = 16 bytes + t.externalformat = GL_RGBA; + t.type = GL_FLOAT; + break; + default: + ASSERT(false); + } + return t; +} + +namespace_end +namespace_end \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/Texture.h b/source/modules/asura-core/Graphics/Texture.h new file mode 100644 index 0000000..7d37c31 --- /dev/null +++ b/source/modules/asura-core/Graphics/Texture.h @@ -0,0 +1,101 @@ +#ifndef _ASURA_TEXTURE_H_ +#define _ASURA_TEXTURE_H_ + +#include +#include + +#include "../CoreConfig.h" + +#include "RenderState.h" +#include "GfxDevice.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +class RenderTarget; + +/// UV采样方式 +enum WrapMode +{ + WRAP_MODE_REPEAT, + WRAP_MODE_MIRROR, + WRAP_MODE_CLAMPTOEDGE, + WRAP_MODE_CLAMPTOBORDER, +}; + +/// 滤波模式 +enum FilterMode +{ + FILTER_MODE_NEAREST, + FILTER_MODE_LINEAR, +}; + +/// 图像数据的颜色格式 +enum ColorFormat +{ + COLOR_FORMAT_UNKNOWN, + COLOR_FORMAT_RGBA8, ///< RGBA都是8bits int + COLOR_FORMAT_RGBA32F, ///< RGBA都是32bits float +}; + +/// 纹理格式,GPU内部和CPU外部格式 +struct TextureFormat +{ + GLenum internalformat; ///< GPU内部格式 + GLenum externalformat; ///< CPU外部格式 + GLenum type; ///< 外部格式每个channel数值类型 +}; + +/// +/// 2D纹理抽象类,在2d mesh和render target中被使用。Texture的渲染原点在左上角,游戏里面的上层会以笛卡尔 +/// 坐标系为标准。在Editor里面界面和组件也是以左上角为原点,这样是为了方便。 +/// +ASURA_ABSTRACT class Texture : public AEScripting::Object +{ +public: + + LUAX_DECL_ABSTRACT_FACTORY(Texture); + + Texture(); + virtual ~Texture(); + + GLuint GetGLTexture() const; + + void SetFilterMode(FilterMode min, FilterMode mag); + void SetWrapMode(WrapMode wrapMode); + + void GetFilterMode(); + void GetWrapMode(); + + /// 如果设置U或V方向filter为 + bool IsGenMipmap(); + +protected: + + /// 转换color format为texture format。 + TextureFormat ConvertColorFormat(const ColorFormat& colorformat); + + GLuint m_TexID; + FilterMode m_MinFilter; + FilterMode m_MagFilter; + WrapMode m_WrapMode; + bool m_IsGenMipmap; + + LUAX_DECL_ENUM(ColorFormat, 1); + LUAX_DECL_ENUM(FilterMode, 1); + LUAX_DECL_ENUM(WrapMode, 1); + + LUAX_DECL_METHOD(_SetFilterMode); + LUAX_DECL_METHOD(_SetWrapMode); + LUAX_DECL_METHOD(_GetFilterMode); + LUAX_DECL_METHOD(_GetWrapMode); + LUAX_DECL_METHOD(_IsGenMipmap); + +}; + +typedef Texture Drawable; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/VertexBuffer.cpp b/source/modules/asura-core/Graphics/VertexBuffer.cpp new file mode 100644 index 0000000..c44e9be --- /dev/null +++ b/source/modules/asura-core/Graphics/VertexBuffer.cpp @@ -0,0 +1,16 @@ +#include "VertexBuffer.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +VertexBuffer::VertexBuffer(BufferUsage usage, BufferDataType datatype, size_t size) + : GPUBuffer(BUFFER_TYPE_VERTEX, usage, datatype, size) +{ +} + +VertexBuffer::~VertexBuffer() +{ +} + +namespace_end +namespace_end diff --git a/source/modules/asura-core/Graphics/VertexBuffer.h b/source/modules/asura-core/Graphics/VertexBuffer.h new file mode 100644 index 0000000..83e9b09 --- /dev/null +++ b/source/modules/asura-core/Graphics/VertexBuffer.h @@ -0,0 +1,34 @@ +#ifndef _ASURA_VERTEX_BUFFER_H_ +#define _ASURA_VERTEX_BUFFER_H_ + +#include + +#include "GPUBuffer.h" + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + +/// +/// 向framework提供了创建显存缓冲的功能,可以直接设置缓冲,绝大多数功能都可以通过此类直接设置顶点数据。 +/// +class VertexBuffer ASURA_FINAL + : public AEScripting::Portable + , public GPUBuffer +{ +public: + + VertexBuffer(BufferUsage usage, BufferDataType datatype, size_t size); + ~VertexBuffer(); + +luaxport: + + LUAX_DECL_FACTORY(VertexBuffer); + + LUAX_DECL_METHOD(_New); + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/binding/_canvas.cpp b/source/modules/asura-core/Graphics/binding/_canvas.cpp new file mode 100644 index 0000000..44841f5 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_canvas.cpp @@ -0,0 +1,48 @@ +#include "../Canvas.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(Canvas) + { + LUAX_REGISTER_METHODS(state, + { "SetSize", _SetSize }, + { "Bind", _Bind }, + { "Unbind", _Unbind } + ); + } + + LUAX_POSTPROCESS(Canvas) + { + + } + + // canvas:SetSize() + LUAX_IMPL_METHOD(Canvas, _SetSize) + { + LUAX_PREPARE(L, Canvas); + return 0; + + } + + // canvas:Bind() + LUAX_IMPL_METHOD(Canvas, _Bind) + { + LUAX_PREPARE(L, Canvas); + + return 0; + } + + // canvas:Unbind() + LUAX_IMPL_METHOD(Canvas, _Unbind) + { + LUAX_PREPARE(L, Canvas); + return 0; + + } + + } +} diff --git a/source/modules/asura-core/Graphics/binding/_color.cpp b/source/modules/asura-core/Graphics/binding/_color.cpp new file mode 100644 index 0000000..008d9c2 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_color.cpp @@ -0,0 +1,130 @@ +#include "../Color.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + +LUAX_REGISTRY(Color) +{ + LUAX_REGISTER_METHODS(state, + { "ToColor32", _ToColor32 }, + { "SetColor", _SetColor }, + { "GetColor", _GetColor }, + { "GetR", _GetR }, + { "GetG", _GetG }, + { "GetB", _GetB }, + { "GetA", _GetA }, + { "__eq", ___eq }, + { "__add", ___add }, + { "__sub", ___sub }, + { "__mul", ___mul }, + { "__div", ___div } + ); +} + +LUAX_POSTPROCESS(Color) +{ + +} + +// color:ToColor32() +LUAX_IMPL_METHOD(Color, _ToColor32) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:SetColor() +LUAX_IMPL_METHOD(Color, _SetColor) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetColor() +LUAX_IMPL_METHOD(Color, _GetColor) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetR() +LUAX_IMPL_METHOD(Color, _GetR) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetG() +LUAX_IMPL_METHOD(Color, _GetG) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetB() +LUAX_IMPL_METHOD(Color, _GetB) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:GetA() +LUAX_IMPL_METHOD(Color, _GetA) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__eq() +LUAX_IMPL_METHOD(Color, ___eq) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__add() +LUAX_IMPL_METHOD(Color, ___add) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__sub() +LUAX_IMPL_METHOD(Color, ___sub) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__mul() +LUAX_IMPL_METHOD(Color, ___mul) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +// color:__div() +LUAX_IMPL_METHOD(Color, ___div) +{ + LUAX_PREPARE(L, Color); + + return 0; +} + +} +} \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/binding/_color32.cpp b/source/modules/asura-core/Graphics/binding/_color32.cpp new file mode 100644 index 0000000..7613361 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_color32.cpp @@ -0,0 +1,66 @@ +#include "../Color32.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(Color32) + { + LUAX_REGISTER_METHODS(state, + { "ToColor", _ToColor }, + { "GetRed", _GetRed }, + { "GetGreen", _GetGreen }, + { "GetBlue", _GetBlue }, + { "GetAlpha", _GetAlpha } + ); + } + + LUAX_POSTPROCESS(Color32) + { + + } + + // color32:ToColor() + LUAX_IMPL_METHOD(Color32, _ToColor) + { + LUAX_PREPARE(L, Color32); + return 0; + + } + + // color32:GetRed() + LUAX_IMPL_METHOD(Color32, _GetRed) + { + LUAX_PREPARE(L, Color32); + return 0; + } + + // color32:GetGreen() + LUAX_IMPL_METHOD(Color32, _GetGreen) + { + LUAX_PREPARE(L, Color32); + + return 0; + } + + // color32:GetBlue() + LUAX_IMPL_METHOD(Color32, _GetBlue) + { + LUAX_PREPARE(L, Color32); + + return 0; + } + + // color32:GetAlpha() + LUAX_IMPL_METHOD(Color32, _GetAlpha) + { + LUAX_PREPARE(L, Color32); + + return 0; + } + + } +} + \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/binding/_gfx_device.cpp b/source/modules/asura-core/Graphics/binding/_gfx_device.cpp new file mode 100644 index 0000000..f6c2004 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_gfx_device.cpp @@ -0,0 +1,151 @@ +#include "../GfxDevice.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(GfxDevice) + { + LUAX_REGISTER_METHODS(state, + { "SetMatrixMode", _SetMatrixMode }, + { "GetMatrixMode", _GetMatrixMode }, + { "PushMatrix", _PushMatrix }, + { "PopMatrix", _PopMatrix }, + { "LoadIdentity", _LoadIdentity }, + { "Rotate", _Rotate }, + { "Translate", _Translate }, + { "Scale", _Scale }, + { "Ortho", _Ortho }, + { "GetMatrixDepth", _GetMatrixDepth }, + { "GetMatrixIndex", _GetMatrixIndex }, + { "UseShader", _UseShader }, + { "UnuseShader", _UnuseShader } + ); + } + + LUAX_POSTPROCESS(GfxDevice) + { + LUAX_REGISTER_ENUM(state, "EMatrixMode", + { "PROJECTION", MATRIX_MODE_PROJECTION }, + { "0", 0 }, + { "MODEL", MATRIX_MODE_MODEL }, + { "1", 1 }, + { "VIEW", MATRIX_MODE_VIEW }, + { "2", 2 } + ); + LUAX_REGISTER_ENUM(state, "EGLParams", + { "MAX_TEXTURE_UNIT", GL_PARAM_MAX_TEXTURE_UNIT }, + { "1", 1 } + ); + + } + + // gfxdevice:SetMatrixMode() + LUAX_IMPL_METHOD(GfxDevice, _SetMatrixMode) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:GetMatrixMode() + LUAX_IMPL_METHOD(GfxDevice, _GetMatrixMode) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:PushMatrix() + LUAX_IMPL_METHOD(GfxDevice, _PushMatrix) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:PopMatrix() + LUAX_IMPL_METHOD(GfxDevice, _PopMatrix) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:LoadIdentity() + LUAX_IMPL_METHOD(GfxDevice, _LoadIdentity) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:Rotate() + LUAX_IMPL_METHOD(GfxDevice, _Rotate) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:Translate() + LUAX_IMPL_METHOD(GfxDevice, _Translate) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:Scale() + LUAX_IMPL_METHOD(GfxDevice, _Scale) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:Ortho() + LUAX_IMPL_METHOD(GfxDevice, _Ortho) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:GetMatrixDepth() + LUAX_IMPL_METHOD(GfxDevice, _GetMatrixDepth) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:GetMatrixIndex() + LUAX_IMPL_METHOD(GfxDevice, _GetMatrixIndex) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:UseShader() + LUAX_IMPL_METHOD(GfxDevice, _UseShader) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + // gfxdevice:UnuseShader() + LUAX_IMPL_METHOD(GfxDevice, _UnuseShader) + { + LUAX_PREPARE(L, GfxDevice); + + return 0; + } + + } +} diff --git a/source/modules/asura-core/Graphics/binding/_gpu_buffer.cpp b/source/modules/asura-core/Graphics/binding/_gpu_buffer.cpp new file mode 100644 index 0000000..8c39a59 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_gpu_buffer.cpp @@ -0,0 +1,118 @@ +#include + +#include "../image.h" +#include "../GPUBuffer.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(GPUBuffer) + { + LUAX_REGISTER_METHODS(state, + { "Fill", _Fill }, + { "GetSize", _GetSize }, + { "GetCount", _GetCount } + ); + } + + LUAX_POSTPROCESS(GPUBuffer) + { + LUAX_REGISTER_ENUM(state, "EBufferType", + { "VERTEX", BUFFER_TYPE_VERTEX }, + { "INDEX", BUFFER_TYPE_INDEX } + ); + LUAX_REGISTER_ENUM(state, "EBufferUsage", + { "STREAM", BUFFER_USAGE_STREAM }, + { "DYNAMIC", BUFFER_USAGE_DYNAMIC }, + { "STATIC", BUFFER_USAGE_STATIC } + ); + LUAX_REGISTER_ENUM(state, "EBufferDataType", + { "INT", BUFFER_DATA_TYPE_INT }, + { "FLOAT", BUFFER_DATA_TYPE_FLOAT }, + { "UNSIGNED_BYTE", BUFFER_DATA_TYPE_UNSIGNED_BYTE } + ); + + } + + // buffer = GPUBuffer.New(bufferType, bufferUsage, bufferDataType, size) + // buffer = GPUBuffer.New(image) + // buffer = GPUBuffer.New(mesh2d) + // buffer = GPUBuffer.New(canvas) + // buffer = GPUBuffer.New(shape) + //LUAX_IMPL_METHOD(GPUBuffer, _New) + //{ + // LUAX_STATE(L); + + // return 0; + //} + + // gpubuffer:Fill({data_unit_list}, offseti) + // data_unit_list :存放数据的table + // offseti : 开始覆盖的地方所在的索引(从0开始) + LUAX_IMPL_METHOD(GPUBuffer, _Fill) + { + LUAX_PREPARE(L, GPUBuffer); + + // 使用buffer对应的类型数据修改buffer,在第一次调用时会初始化size大小的buffer,然后填充。 + int offset = state.GetValue(3, 0); + int count = lua_objlen(L, 2); + int size = count * self->GetDataTypeSize(); + byte* data = (byte*)malloc(size); + int unit = self->GetDataTypeSize(); + int i = 1; + lua_rawgeti(L, 2, i); + while (!lua_isnil(L, -1)) + { + switch (self->m_DataType) + { + case GL_INT: + { + int n = state.CheckValue(-1); + memcpy(data + (i - 1)*unit, &n, unit); + break; + } + case GL_FLOAT: + { + float n = state.CheckValue(-1); + memcpy(data + (i - 1)*unit, &n, unit); + break; + } + case GL_UNSIGNED_BYTE: + { + unsigned char n = state.CheckValue(-1); + memcpy(data + (i - 1)*unit, &n, unit); + break; + } + } + state.Pop(1); // value + lua_rawgeti(L, 2, ++i); + } + state.Pop(); // nil + + self->Fill(data, size, offset * unit); + + free(data); + return 0; + } + + // gpubuffer:GetSize() + LUAX_IMPL_METHOD(GPUBuffer, _GetSize) + { + LUAX_PREPARE(L, GPUBuffer); + state.Push(self->m_Size); + return 0; + } + + LUAX_IMPL_METHOD(GPUBuffer, _GetCount) + { + LUAX_PREPARE(L, GPUBuffer); + state.Push(self->m_Size / self->GetDataTypeSize()); + return 0; + } + + } +} diff --git a/source/modules/asura-core/Graphics/binding/_image.cpp b/source/modules/asura-core/Graphics/binding/_image.cpp new file mode 100644 index 0000000..0e4cb16 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_image.cpp @@ -0,0 +1,71 @@ +#include "../image.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(Image) + { + LUAX_INHERIT(state, Texture); + + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "GetWidth", _GetWidth }, + { "GetHeight", _GetHeight }, + { "GetSize", _GetSize }, + { "Render", _Render } + ); + } + + LUAX_POSTPROCESS(Image) + { + } + + // image = Image.New() + LUAX_IMPL_METHOD(Image, _New) + { + LUAX_STATE(L); + Image* img = new Image(); + img->PushLuaxUserdata(state); + return 1; + } + + // width = image:GetWidth() + LUAX_IMPL_METHOD(Image, _GetWidth) + { + LUAX_PREPARE(L, Image); + state.Push(self->GetWidth()); + return 1; + } + + // height = image:GetHeight() + LUAX_IMPL_METHOD(Image, _GetHeight) + { + LUAX_PREPARE(L, Image); + state.Push(self->GetHeight()); + return 1; + } + + // width, height = image:GetSize() + LUAX_IMPL_METHOD(Image, _GetSize) + { + LUAX_PREPARE(L, Image); + int width = self->GetWidth(); + int height = self->GetHeight(); + state.Push(width); + state.Push(height); + return 2; + } + + // image:Render() + LUAX_IMPL_METHOD(Image, _Render) + { + LUAX_PREPARE(L, Image); + + return 0; + } + + } +} diff --git a/source/modules/asura-core/Graphics/binding/_index_buffer.cpp b/source/modules/asura-core/Graphics/binding/_index_buffer.cpp new file mode 100644 index 0000000..151dc98 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_index_buffer.cpp @@ -0,0 +1,31 @@ +#include "../IndexBuffer.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(IndexBuffer) + { + LUAX_REGISTER_METHODS(state, + { "New", _New } + ); + } + + LUAX_POSTPROCESS(IndexBuffer) + { + + } + + // IndexBuffer.New() + LUAX_IMPL_METHOD(IndexBuffer, _New) + { + LUAX_STATE(L); + + return 0; + } + + } +} diff --git a/source/modules/asura-core/Graphics/binding/_mesh2d.cpp b/source/modules/asura-core/Graphics/binding/_mesh2d.cpp new file mode 100644 index 0000000..4e3f426 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_mesh2d.cpp @@ -0,0 +1,20 @@ +#include "../mesh2d.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(Mesh2D) + { + + } + + LUAX_POSTPROCESS(Mesh2D) + { + + } + + } +} diff --git a/source/modules/asura-core/Graphics/binding/_shader.cpp b/source/modules/asura-core/Graphics/binding/_shader.cpp new file mode 100644 index 0000000..85fd388 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_shader.cpp @@ -0,0 +1,131 @@ +#include "../shader.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(Shader) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "Load", _Load }, + { "Update", _Update }, + { "HasUniform", _HasUniform }, + { "GetUniformLocation", _GetUniformLocation }, + { "SetBuiltInUniforms", _SetBuiltInUniforms }, + { "SetUniformFloat", _SetUniformFloat }, + { "SetUniformTexture", _SetUniformTexture }, + { "SetUniformVector2", _SetUniformVector2 }, + { "SetUniformVector3", _SetUniformVector3 }, + { "SetUniformVector4", _SetUniformVector4 }, + { "SetUniformColor", _SetUniformColor }, + { "SetBuiltInUniforms", _SetBuiltInUniforms } + ); + } + + LUAX_POSTPROCESS(Shader) + { + + } + + // Shader.New() + LUAX_IMPL_METHOD(Shader, _New) + { + LUAX_STATE(L); + + return 0; + } + + // shader:Load() + LUAX_IMPL_METHOD(Shader, _Load) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:Update() + LUAX_IMPL_METHOD(Shader, _Update) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:HasUniform() + LUAX_IMPL_METHOD(Shader, _HasUniform) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:GetUniformLocation() + LUAX_IMPL_METHOD(Shader, _GetUniformLocation) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetBuiltInUniforms() + LUAX_IMPL_METHOD(Shader, _SetBuiltInUniforms) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformFloat() + LUAX_IMPL_METHOD(Shader, _SetUniformFloat) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformTexture() + LUAX_IMPL_METHOD(Shader, _SetUniformTexture) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformVector2() + LUAX_IMPL_METHOD(Shader, _SetUniformVector2) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformVector3() + LUAX_IMPL_METHOD(Shader, _SetUniformVector3) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformVector4() + LUAX_IMPL_METHOD(Shader, _SetUniformVector4) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + // shader:SetUniformColor() + LUAX_IMPL_METHOD(Shader, _SetUniformColor) + { + LUAX_PREPARE(L, Shader); + + return 0; + } + + } +} diff --git a/source/modules/asura-core/Graphics/binding/_sprite_batch.cpp b/source/modules/asura-core/Graphics/binding/_sprite_batch.cpp new file mode 100644 index 0000000..6b7d25c --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_sprite_batch.cpp @@ -0,0 +1,20 @@ +#include "../SpriteBatch.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(SpriteBatch) + { + + } + + LUAX_POSTPROCESS(SpriteBatch) + { + + } + + } +} diff --git a/source/modules/asura-core/Graphics/binding/_texture.cpp b/source/modules/asura-core/Graphics/binding/_texture.cpp new file mode 100644 index 0000000..f5e5f17 --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_texture.cpp @@ -0,0 +1,85 @@ +#include "../texture.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(Texture) + { + LUAX_REGISTER_METHODS(state, + { "SetFilterMode", _SetFilterMode }, + { "SetWrapMode", _SetWrapMode }, + { "GetFilterMode", _GetFilterMode }, + { "GetWrapMode", _GetWrapMode }, + { "IsGenMipmap", _IsGenMipmap } + ); + } + + LUAX_POSTPROCESS(Texture) + { + LUAX_REGISTER_ENUM(state, "EColorFormat", + { "UNKNOWN", COLOR_FORMAT_UNKNOWN }, + { "RGBA8", COLOR_FORMAT_RGBA8 }, + { "RGBA32F", COLOR_FORMAT_RGBA32F } + ); + LUAX_REGISTER_ENUM(state, "EFilterMode", + { "NEAREST", FILTER_MODE_NEAREST }, + { "LINEAR", FILTER_MODE_LINEAR } + ); + LUAX_REGISTER_ENUM(state, "EWrapMode", + { "REPEAT", WRAP_MODE_REPEAT }, + { "MIRROR", WRAP_MODE_MIRROR }, + { "CLAMPTOEDGE", WRAP_MODE_CLAMPTOEDGE }, + { "CLAMPTOBORDER", WRAP_MODE_CLAMPTOBORDER } + ); + + } + + // texture:SetFilterMode(minFilter, magFilter) + LUAX_IMPL_METHOD(Texture, _SetFilterMode) + { + LUAX_PREPARE(L, Texture); + FilterMode min = (FilterMode)state.CheckValue(2); + FilterMode mag = (FilterMode)state.CheckValue(3); + self->SetFilterMode(min, mag); + return 0; + } + + // texture:SetWrapMode(wrap_mode) + LUAX_IMPL_METHOD(Texture, _SetWrapMode) + { + LUAX_PREPARE(L, Texture); + WrapMode wrap_mode = (WrapMode)state.CheckValue(2); + self->SetWrapMode(wrap_mode); + return 0; + } + + // min, mag = texture:GetFilterMode() + LUAX_IMPL_METHOD(Texture, _GetFilterMode) + { + LUAX_PREPARE(L, Texture); + state.Push((int)self->m_MinFilter); + state.Push((int)self->m_MagFilter); + return 2; + } + + // wrapmode= texture:GetWrapMode() + LUAX_IMPL_METHOD(Texture, _GetWrapMode) + { + LUAX_PREPARE(L, Texture); + state.Push((int)self->m_WrapMode); + return 1; + } + + // texture:IsGenMipmap() + LUAX_IMPL_METHOD(Texture, _IsGenMipmap) + { + LUAX_PREPARE(L, Texture); + state.Push(self->IsGenMipmap()); + return 1; + } + + } +} \ No newline at end of file diff --git a/source/modules/asura-core/Graphics/binding/_vertex_buffer.cpp b/source/modules/asura-core/Graphics/binding/_vertex_buffer.cpp new file mode 100644 index 0000000..8ed487b --- /dev/null +++ b/source/modules/asura-core/Graphics/binding/_vertex_buffer.cpp @@ -0,0 +1,38 @@ +#include "../VertexBuffer.h" + +using namespace std; +using namespace Luax; + +namespace_begin(AsuraEngine) +namespace_begin(Graphics) + + + LUAX_REGISTRY(VertexBuffer) + { + LUAX_REGISTER_METHODS(state, + { "New", _New } + ); + } + + LUAX_POSTPROCESS(VertexBuffer) + { + + } + + // vbo = VertexBuffer.New(usage, data_type, count) + LUAX_IMPL_METHOD(VertexBuffer, _New) + { + LUAX_STATE(L); + + BufferUsage usage = (BufferUsage)state.CheckValue(1); + BufferDataType datatype = (BufferDataType)state.CheckValue(2); + uint count = state.CheckValue(3); + + VertexBuffer* vbo = new VertexBuffer(usage, datatype, count * GPUBuffer::GetDataTypeSize(datatype)); + vbo->PushLuaxUserdata(state); + + return 1; + } + + } +} diff --git a/source/modules/asura-core/Image/ImageData.cpp b/source/modules/asura-core/Image/ImageData.cpp new file mode 100644 index 0000000..c75166f --- /dev/null +++ b/source/modules/asura-core/Image/ImageData.cpp @@ -0,0 +1,62 @@ +#include "ImageData.h" +#include "PngDecoder.h" +#include "StbDecoder.h" +#include "ImageDecoder.h" + +using namespace std; + +using namespace AEGraphics; + +namespace_begin(AsuraEngine) +namespace_begin(Image) + +// 解析image的decoder,用来作为解析策略。 +list ImageData::ImageDecoders = { + new PNGDecoder(), // png + new STBDecoder() // jpeg, tga, bmp +}; + +ImageData::ImageData() + : pixels(nullptr) + , size(0) + , width(0) + , height(0) + , format(COLOR_FORMAT_UNKNOWN) +{ +} + +ImageData::~ImageData() +{ + if (pixels) + delete[] pixels; +} + +void ImageData::Decode(IO::DataBuffer& buffer) +{ + for (ImageDecoder* decoder : ImageDecoders) + { + if (decoder->CanDecode(buffer)) + { + decoder->Decode(buffer, *this); + return; + } + } +} + +Color ImageData::GetPixel(uint x, uint y) +{ + return Color(); +} + +void ImageData::Lock() +{ + m_Mutex.Lock(); +} + +void ImageData::Unlock() +{ + m_Mutex.Unlock(); +} + +namespace_end +namespace_end \ No newline at end of file diff --git a/source/modules/asura-core/Image/ImageData.h b/source/modules/asura-core/Image/ImageData.h new file mode 100644 index 0000000..cd2fe1a --- /dev/null +++ b/source/modules/asura-core/Image/ImageData.h @@ -0,0 +1,81 @@ +#ifndef _ASURA_ENGINE_IMAGEDATA_H_ +#define _ASURA_ENGINE_IMAGEDATA_H_ + +#include + +#include +#include +#include +#include +#include + +#include "../Graphics/Texture.h" +#include "../Graphics/Color.h" + +namespace_begin(AsuraEngine) +namespace_begin(Image) + +class ImageDecoder; + +class ImageData ASURA_FINAL + : public Scripting::Portable + , public AEIO::DecodedData +{ +public: + + /// + /// 解析图片数据文件,并构建像素信息,如果解析失败,抛出异常 + /// + ImageData(); + ~ImageData(); + + void Decode(AEIO::DataBuffer& buffer) override; + + void Lock(); + void Unlock(); + + AEGraphics::Color GetPixel(uint x, uint y); + + //----------------------------------------------------------------------------// + + uint width, height; // 像素尺寸 + AEGraphics::ColorFormat format; // 格式 + byte* pixels; // 像素数据 + std::size_t size; // 数据长度 + + //----------------------------------------------------------------------------// + +private: + + /// + /// 在第一次准备image data时构建所有提供的decoder。在几个decoders中间选择解析策略。 + /// + static std::list ImageDecoders; + + /// + /// 写数据的锁。 + /// + AEThreading::Mutex m_Mutex; + +luaxport: + + LUAX_DECL_FACTORY(ImageData); + + LUAX_DECL_METHOD(_New); + LUAX_DECL_METHOD(_GetPixel); + LUAX_DECL_METHOD(_GetSize); + LUAX_DECL_METHOD(_GetWidth); + LUAX_DECL_METHOD(_GetHeight); + LUAX_DECL_METHOD(_GetPixelFormat); + LUAX_DECL_METHOD(_Decode); + LUAX_DECL_METHOD(_DecodeAsync); + LUAX_DECL_METHOD(_IsAvailable); + +}; + +namespace_end +namespace_end + +namespace AEImage = AsuraEngine::Image; + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Image/ImageDecodeTask.cpp b/source/modules/asura-core/Image/ImageDecodeTask.cpp new file mode 100644 index 0000000..16c166e --- /dev/null +++ b/source/modules/asura-core/Image/ImageDecodeTask.cpp @@ -0,0 +1,17 @@ +#include "ImageDecodeTask.h" + +namespace_begin(AsuraEngine) +namespace_begin(Image) + +bool ImageDecodeTask::Execute() +{ + return false; +} + +void ImageDecodeTask::Invoke(lua_State* invokeThreaad) +{ + +} + +namespace_end +namespace_end \ No newline at end of file diff --git a/source/modules/asura-core/Image/ImageDecodeTask.h b/source/modules/asura-core/Image/ImageDecodeTask.h new file mode 100644 index 0000000..74ecf24 --- /dev/null +++ b/source/modules/asura-core/Image/ImageDecodeTask.h @@ -0,0 +1,35 @@ +#ifndef _ASURA_IMAGE_DECODE_TASK_H_ +#define _ASURA_IMAGE_DECODE_TASK_H_ + +#include +#include +#include + +namespace_begin(AsuraEngine) +namespace_begin(Image) + +class ImageDecodeTask + : public AEScripting::Portable +{ +public: + + /// + /// 执行任务,完成后返回true,调用回调函数。 + /// + bool Execute() override; + + /// + /// 调用回调。在invoke thread里面回调。 + /// + void Invoke(lua_State* invokeThreaad) override; + +luaxport: + + LUAX_DECL_FACTORY(ImageDecodeTask, AEThreading::Task); + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Image/ImageDecoder.h b/source/modules/asura-core/Image/ImageDecoder.h new file mode 100644 index 0000000..7de92d6 --- /dev/null +++ b/source/modules/asura-core/Image/ImageDecoder.h @@ -0,0 +1,33 @@ +#ifndef _ASURA_ENGINE_IMAGE_DECODER_H_ +#define _ASURA_ENGINE_IMAGE_DECODER_H_ + +#include + +#include "ImageData.h" + +namespace_begin(AsuraEngine) +namespace_begin(Image) + +ASURA_ABSTRACT class ImageDecoder +{ +public: + + ImageDecoder() {}; + virtual ~ImageDecoder() {}; + + /// + /// 判断内存是否能用本decoder解压 + /// + virtual bool CanDecode(AEIO::DataBuffer& input) = 0; + + /// + /// 输入一个编码后的内存,输出一个解压后的Image data,如果解压失败返回nullptr + /// + virtual void Decode(AEIO::DataBuffer& input, ImageData& target) = 0; + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Image/PngDecoder.cpp b/source/modules/asura-core/Image/PngDecoder.cpp new file mode 100644 index 0000000..618c16e --- /dev/null +++ b/source/modules/asura-core/Image/PngDecoder.cpp @@ -0,0 +1,17 @@ +#include "PngDecoder.h" + +namespace_begin(AsuraEngine) +namespace_begin(Image) + +bool PNGDecoder::CanDecode(AEIO::DataBuffer& buffer) +{ + return false; +} + +void PNGDecoder::Decode(AEIO::DataBuffer& buffer, ImageData& data) +{ + +} + +namespace_end +namespace_end diff --git a/source/modules/asura-core/Image/PngDecoder.h b/source/modules/asura-core/Image/PngDecoder.h new file mode 100644 index 0000000..b6ea3ba --- /dev/null +++ b/source/modules/asura-core/Image/PngDecoder.h @@ -0,0 +1,25 @@ +#ifndef _ASURA_ENGINE_PNGDECODER_H_ +#define _ASURA_ENGINE_PNGDECODER_H_ + +#include "ImageDecoder.h" + +namespace_begin(AsuraEngine) +namespace_begin(Image) + +/// +/// 使用lodepng解压png文件 +/// +class PNGDecoder ASURA_FINAL: public ImageDecoder +{ +public: + + bool CanDecode(AEIO::DataBuffer& buffer) override; + + void Decode(AEIO::DataBuffer& buffer, ImageData& data) override; + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Image/StbDecoder.cpp b/source/modules/asura-core/Image/StbDecoder.cpp new file mode 100644 index 0000000..8d3537c --- /dev/null +++ b/source/modules/asura-core/Image/StbDecoder.cpp @@ -0,0 +1,73 @@ +#include + +#include "StbDecoder.h" + +#define STB_IMAGE_IMPLEMENTATION +#include + +using namespace AEGraphics; + +namespace_begin(AsuraEngine) +namespace_begin(Image) + +bool STBDecoder::CanDecode(IO::DataBuffer& buffer) +{ + int w = 0; + int h = 0; + int comp = 0; + + int status = stbi_info_from_memory((const stbi_uc*)buffer.GetData(), buffer.GetSize(), &w, &h, &comp); + + return status == 1 && w > 0 && h > 0; +} + +void STBDecoder::Decode(IO::DataBuffer& db, ImageData& imageData) +{ + const stbi_uc *buffer = (const stbi_uc *)db.GetData(); + // databuffer数据长 + int bufferlen = db.GetSize(); + + int width, height; + int comp = 0; + byte* data = nullptr; + ColorFormat format = COLOR_FORMAT_UNKNOWN; + std::size_t size = 0; + + if (stbi_is_hdr_from_memory(buffer, bufferlen)) + { + // 4个channel都是float + data = (byte*)stbi_loadf_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); + format = COLOR_FORMAT_RGBA32F; + size = width * height * 4 * sizeof(float); + } + else + { + data = (byte*)stbi_load_from_memory(buffer, bufferlen, &width, &height, &comp, STBI_rgb_alpha); + format = COLOR_FORMAT_RGBA8; + size = width * height * 4; + } + if (data) + { + imageData.Lock(); + + if (imageData.pixels) + free(imageData.pixels); + imageData.pixels = (byte*)data; + imageData.format = format; + imageData.width = width; + imageData.height = height; + imageData.size = size; + + imageData.Unlock(); + } + else + { + const char *err = stbi_failure_reason(); + if (err == nullptr) + err = "unknown error"; + throw Exception("Could not decode image with stb_image (%s).", err); + } +} + +namespace_end +namespace_end \ No newline at end of file diff --git a/source/modules/asura-core/Image/StbDecoder.h b/source/modules/asura-core/Image/StbDecoder.h new file mode 100644 index 0000000..a86073a --- /dev/null +++ b/source/modules/asura-core/Image/StbDecoder.h @@ -0,0 +1,26 @@ +#ifndef _ASURA_ENGINE_STBDECODER_H_ +#define _ASURA_ENGINE_STBDECODER_H_ + +#include "ImageDecoder.h" + +namespace_begin(AsuraEngine) +namespace_begin(Image) + +/// +/// 使用stb_image解压JPEG、TGA、BMP文件 +/// +class STBDecoder ASURA_FINAL + : public ImageDecoder +{ +public: + + bool CanDecode(AEIO::DataBuffer& buffer) override; + + void Decode(AEIO::DataBuffer& buffer, ImageData& data) override; + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Image/binding/_image_data.cpp b/source/modules/asura-core/Image/binding/_image_data.cpp new file mode 100644 index 0000000..77f3a96 --- /dev/null +++ b/source/modules/asura-core/Image/binding/_image_data.cpp @@ -0,0 +1,108 @@ +#include +#include + +#include "../ImageData.h" + +using namespace std; +using namespace AEThreading; +using namespace AEIO; + +namespace_begin(AsuraEngine) +namespace_begin(Image) +LUAX_REGISTRY(ImageData) + { + LUAX_REGISTER_METHODS(state, + { "New", _New }, + { "GetPixel", _GetPixel }, + { "GetSize", _GetSize }, + { "GetWidth", _GetWidth }, + { "GetHeight", _GetHeight }, + { "GetPixelFormat", _GetPixelFormat }, + { "Decode", _Decode }, + { "DecodeAsync", _DecodeAsync }, + { "IsAvailable", _IsAvailable } + ); + } + + LUAX_POSTPROCESS(ImageData) + { + + } + + // ImageData.New() + LUAX_IMPL_METHOD(ImageData, _New) + { + LUAX_STATE(L); + + return 0; + } + + // imagedata:GetPixel() + LUAX_IMPL_METHOD(ImageData, _GetPixel) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:GetSize() + LUAX_IMPL_METHOD(ImageData, _GetSize) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:GetWidth() + LUAX_IMPL_METHOD(ImageData, _GetWidth) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:GetHeight() + LUAX_IMPL_METHOD(ImageData, _GetHeight) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:GetPixelFormat() + LUAX_IMPL_METHOD(ImageData, _GetPixelFormat) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:Decode() + LUAX_IMPL_METHOD(ImageData, _Decode) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + // imagedata:DecodeAsync(thread, databuffer, callback) + LUAX_IMPL_METHOD(ImageData, _DecodeAsync) + { + LUAX_PREPARE(L, ImageData); + + Thread* thread = state.CheckUserdata(2); + DataBuffer* buffer = state.CheckUserdata(3); + + return 0; + } + + // imagedata:IsAvailable() + LUAX_IMPL_METHOD(ImageData, _IsAvailable) + { + LUAX_PREPARE(L, ImageData); + + return 0; + } + + } +} diff --git a/source/modules/asura-core/Image/binding/_image_decode_task.cpp b/source/modules/asura-core/Image/binding/_image_decode_task.cpp new file mode 100644 index 0000000..3c8ed4b --- /dev/null +++ b/source/modules/asura-core/Image/binding/_image_decode_task.cpp @@ -0,0 +1,19 @@ +#include "../ImageDecodeTask.h" + +using namespace std; + +namespace_begin(AsuraEngine) +namespace_begin(Image) + +LUAX_REGISTRY(ImageDecodeTask) +{ + +} + +LUAX_POSTPROCESS(ImageDecodeTask) +{ + +} + +} +} diff --git a/source/modules/asura-core/Input/Button.h b/source/modules/asura-core/Input/Button.h new file mode 100644 index 0000000..5c3c0de --- /dev/null +++ b/source/modules/asura-core/Input/Button.h @@ -0,0 +1,31 @@ +#ifndef __BUTTON_H__ +#define __BUTTON_H__ + +#include + +namespace_begin(AsuraEngine) +namespace_begin(Input) + +/// keyboard button \ mouse button \ joystick button +class Button +{ +public: + inline Button(int key, bool state) : + key(key), + state(state) + { + } + + inline int GetKey(void) const { return this->key; } + inline bool GetState(void) const { return this->state; } + +private: + int key; + bool state; + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Input/ClipBoard.cpp b/source/modules/asura-core/Input/ClipBoard.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/Input/ClipBoard.h b/source/modules/asura-core/Input/ClipBoard.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/Input/InputDevice.cpp b/source/modules/asura-core/Input/InputDevice.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/Input/InputDevice.h b/source/modules/asura-core/Input/InputDevice.h new file mode 100644 index 0000000..39f3d37 --- /dev/null +++ b/source/modules/asura-core/Input/InputDevice.h @@ -0,0 +1,39 @@ +#ifndef _ASURA_ENGINE_INPUT_BASE_H_ +#define _ASURA_ENGINE_INPUT_BASE_H_ + +#include +#include +#include + +#include "../CoreConfig.h" + +#include "KeyboardState.h" + +namespace_begin(AsuraEngine) +namespace_begin(Input) + +/// 不同平台继承这个基类并实现handle接口 +ASURA_ABSTRACT class InputDevice : public Singleton +{ +protected: + + void OnKeyDown(int key); + void OnKeyUp(int key); + + void OnMouseMove(const AEMath::Vector2f& position); + + void OnMouseButtonDown(int key); + void OnMouseButtonUp(int key); + + void OnMouseWheel(); + + void OnInputChar(); + +}; + +namespace_end +namespace_end + +namespace AEInput = AsuraEngine::Input; + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Input/InputManager.cpp b/source/modules/asura-core/Input/InputManager.cpp new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/Input/InputManager.h b/source/modules/asura-core/Input/InputManager.h new file mode 100644 index 0000000..dd11b2f --- /dev/null +++ b/source/modules/asura-core/Input/InputManager.h @@ -0,0 +1,24 @@ +#ifndef __INPUT_MAMANGER_H__ +#define __INPUT_MAMANGER_H__ + +#include +#include +#include + +namespace_begin(AsuraEngine) +namespace_begin(Input) + +/// 逻辑管理 +class InputManager : public Singleton +{ +public : + + +private : + +}; + +namespace_end +namespace_end + +#endif \ No newline at end of file diff --git a/source/modules/asura-core/Input/JoystickState.h b/source/modules/asura-core/Input/JoystickState.h new file mode 100644 index 0000000..e69de29 diff --git a/source/modules/asura-core/Input/KeyboardState.h b/source/modules/asura-core/Input/KeyboardState.h new file mode 100644 index 0000000..96d22e7 --- /dev/null +++ b/source/modules/asura-core/Input/KeyboardState.h @@ -0,0 +1,37 @@ +#ifndef __KEYBOARD_STATE_H__ +#define __KEYBOARD_STATE_H__ + +#include + +#include "Button.h" + +namespace_begin(AsuraEngine) +namespace_begin(Input) + +typedef std::vector