diff --git a/README.md b/README.md index fcf63f6752f70ce629872d89e164533ce1765f53..cf2203e55e0532f13a0d111992b82da15fef3aa8 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,21 @@ While the project was originally developed on macOS, it was later ported to Wind Dependencies are OpenGL, ImGui and SDL, and all of them are contained in this repository. +For a general overview of the application logic, one should have a look at the [Architecture](#architecture) section. +An accompanying code example is shown in [Workflow: Sample Main Function](#workflow-sample-main-function). + +If one desires to add custom resources (e.g. new predefined structures or a new colour palette), one should head straight to [Resources](#resources) section, +where the resource organization and file format conventions are detailed. + +For information on how the project can be built, the [Building the Project](#building-the-project) section has you covered with step-by-step instructions. + +In depth documentation about all classes and their members can be found in the [Classes](#classes) section. Enums are covered in their own [Enums](#enums-enumshpp) section. + +While DearImGui is the basis for the GUI front- and backend, I had to perform some modifications in order to make it work on a touchscreen. +Those changes are detailed in the section [ImGui Customization](#imgui-customization). + +Finally, shaders and their respective purposes are explained in the section [GLSL Shaders](#glsl-shaders). + # Table of Contents [TOC] @@ -19,7 +34,8 @@ The repo is organized in the following folders: - `build` is left over from the macOS days (contains a currently broken `Makefile`) # Resources -Resources are organized in a single folder called `ft_top`. It contains the following: +## Runtime Resource Folder +Runtime resources are organized in a single folder called `ft_top`. It contains the following: - A folder `bin` that contains the executable and `SDL2.dll` - A folder `fonts` that contains the font used by the GUI, namely `Cousine-Regular.ttf` - A folder `resource` that contains @@ -46,7 +62,7 @@ To be save, I'll state that images are expected to be loadable with the above ca ### Damping Textures Damping Textures, such as those used by `PatternHandler` and `WaveHandler`, are 2D textures and they are composed of two files: - a `.conf` file that describes several properties of the texture, -- a `.texture` file that contains the texture data. +- a `.texture` file that contains the texture data in RGBA32F format. These two files are expected to be in the same directory. By convention, the name of the texture does never include any file extensions. Thus a texture with name `my_damping_map` will consist of the two files `my_damping_map.conf` and `my_damping_map.texture`. @@ -71,8 +87,10 @@ That's what these offsets describe. Note that only if all damping textures agree with the dimensions specified in the application, will the program run correctly. Anything else will give you UB. -A `.texture` file contains `4 * texture_width * texture_height` floating point values. Each group of four is to be interpreted as the RGBA values of a single texel. -Successive values are delimited with a single space. After each `4 * texture_width` values, a newline is expected. +A `.texture` file contains `4 * texture_width * texture_height` floating point values, each in the range [0,1]; 0 means this channel is fully off, while 1 means the channel is fully on. Each group of four is to be interpreted as the RGBA values of a single texel. +Successive values are delimited with a single space. Each group of four float describes the colour of one texel in the format R G B A. After each `4 * texture_width` values, a newline is expected. +The only channel that matters for now is the red channel. Damping is multiplicative, such that more red means less damping. +For more information on how damping is implemented, study how the damping texture `tex_damp` comes into play in the timestepping [fragment shader](shaders/stepwave.frag). Texture uploading is done via the following call: ```c++ @@ -140,9 +158,6 @@ In order to build the project, the following steps must be followed ## macOS Building on macOS is currently not supported. -# User Manual -Todo - # Documentation The following is a documentation for all the code used in the project. As the project is currently at development halt, there are a few known issues that can not be addressed for the time being. They are pointed out in their respective sections. ## Architecture @@ -196,6 +211,12 @@ The logical flow of the application game loop goes as follows: For an example how this is implemented in practice, see [Sample Main Function](#workflow-sample-main-function) ## Classes + +### A General Note on Pre-/Postconditions +Sensible preconditions to functions are always implicit. +I.e. it is generally assumed that objects are fully and correctly initialized, except when this can obviously not be the case (e.g. for a function `initialize`). +Only "special" preconditions are listed. The same is true for postconditions. + ### Drawer ([drawer.hpp](include/drawer.hpp), [drawer.cpp](src/drawer.cpp)) **Description** @@ -258,16 +279,16 @@ For an example how this is implemented in practice, see [Sample Main Function](# **Public Data Members** -N/A +None **Private Data Members** -- `float x0_, y0_, x1_, y1_`: Internal representation of old ('0') and new ('1') points. -- `int num_drawn_`: Number of calls to `draw` and `erase`. -- `std::vector<float> points_`: Vertex coordinates that represent the stroke between old and new points, as calculated by `calculate_points_`. +- **`float x0_, y0_, x1_, y1_`**: Internal representation of old ('0') and new ('1') points. +- **`int num_drawn_`**: Number of calls to `draw` and `erase`. +- **`std::vector<float> points_`**: Vertex coordinates that represent the stroke between old and new points, as calculated by `calculate_points_`. **Notes** -N/A +None ### DrawingHandler ([drawing_handler.hpp](include/drawing_handler.hpp), [drawing_handler.cpp](src/drawing_handler.cpp)) **Description** @@ -315,21 +336,19 @@ This class handles all aspects of the `Zeichnen` / `Radieren` functionality. It **Public Data Members** -N/A +None **Private Data Members** -- `std::list<std::pair<Drawer, SDL_FingerID> > drawpairs_`: List of `Drawer`s and the corresponding `SDL_FingerID` that spawned/controls them. -- `int previous_mstate_`: `tb.mstate` from previous frame -- `float draw_value_, erase_value_`: **DEPRECATED** -- `GLuint vao_, vbo_`: Vertex Array Object and Vertex Buffer Object that are used by the `Drawer`s -- `GLuint fbo_, fbo_wave_`: Framebuffers that target the static damping texture (`fbo_`) and the wave texture 1 (`fbo_wave_`) -- `Shader shader_draw_`: Shader that is used. +- **`std::list<std::pair<Drawer, SDL_FingerID> > drawpairs_`**: List of `Drawer`s and the corresponding `SDL_FingerID` that spawned/controls them. +- **`int previous_mstate_`**: `tb.mstate` from previous frame +- **`float draw_value_, erase_value_`**: **DEPRECATED** +- **`GLuint vao_, vbo_`**: Vertex Array Object and Vertex Buffer Object that are used by the `Drawer`s +- **`GLuint fbo_, fbo_wave_`**: Framebuffers that target the static damping texture (`fbo_`) and the wave texture 1 (`fbo_wave_`) +- **`Shader shader_draw_`**: Shader that is used. **Notes** -Todo - ### EfficientBlock ([efficient_block.hpp](include/efficient_block.hpp), [efficient_block.cpp](src/efficient_block.cpp)) **Description** @@ -394,21 +413,19 @@ Represents a rectangular block. Scaled down version of the previous `Block`, opt **Private Function Members** -N/A +None **Public Data Members** -N/A +None **Private Data Members** -- `glm::ivec4 xywh_`: Coordinates and dimensions of block -- `bool needs_removal_`: Is block marked for removal? +- **`glm::ivec4 xywh_`**: Coordinates and dimensions of block +- **`bool needs_removal_`**: Is block marked for removal? **Notes** -Todo - ### EventLogger ([event_logger.hpp](include/event_logger.hpp), [event_logger.cpp](src/event_logger.cpp)) **Description** @@ -445,23 +462,23 @@ Logs events directly from the `Toolbox` and sorts them by type in 16-deep circul **Private Function Members** -N/A +None **Public Data Members** -- `unsigned i_down, i_up, i_move, i_other`: Index where next event is to be inserted. -- `std::array<Pevent, 16> events_down`: Events of down-type. -- `std::array<Pevent, 16> events_up`: Events of up-type. -- `std::array<Pevent, 16> events_move`: Events of move-type. -- `std::array<Pevent, 16> events_other`: Events of other-type. +- **`unsigned i_down, i_up, i_move, i_other`**: Index where next event is to be inserted. +- **`std::array<Pevent, 16> events_down`**: Events of down-type. +- **`std::array<Pevent, 16> events_up`**: Events of up-type. +- **`std::array<Pevent, 16> events_move`**: Events of move-type. +- **`std::array<Pevent, 16> events_other`**: Events of other-type. **Private Data Members** -N/A +None **Notes** -N/A +None ### GuiHandler ([gui_handler.hpp](include/gui_handler.hpp), [gui_handler.cpp](src/gui_handler.cpp)) **Description** @@ -539,24 +556,24 @@ Draws and controls all functionality related to the GUI. **Public Data Members** -N/A +None **Private Data Members** -- `float gui_pos_`: Portion of screen occupied by GUI -- `ImGuiIO io_`: ImGui IO object -- `SDL_Event next_event_`: Next event for event chains that span several frames (raising, lowering finger) -- `SDL_FingerID fingerID_`: Finger currently controlling the GUI -- `SDL_TouchID deviceID_`: ID of the currently connected touch device (read: touchscreen) -- `bool lowering_finger_`: Are we in the event chain of lowering a finger? -- `bool raising_finger_`: Are we in the event chain of raising a finger? -- `ImFont* font_`: Font used by ImGui -- `GLuint btex_*_on, btex_*_off`: 12 OpenGL texture handles corresponding to images drawn in GUI -- `EventLogger evlog`: EventLogger, only present while debugging +- **`float gui_pos_`**: Portion of screen occupied by GUI +- **`ImGuiIO io_`**: ImGui IO object +- **`SDL_Event next_event_`**: Next event for event chains that span several frames (raising, lowering finger) +- **`SDL_FingerID fingerID_`**: Finger currently controlling the GUI +- **`SDL_TouchID deviceID_`**: ID of the currently connected touch device (read: touchscreen) +- **`bool lowering_finger_`**: Are we in the event chain of lowering a finger? +- **`bool raising_finger_`**: Are we in the event chain of raising a finger? +- **`ImFont* font_`**: Font used by ImGui +- **`GLuint btex_*_on, btex_*_off`**: 12 OpenGL texture handles corresponding to images drawn in GUI +- **`EventLogger evlog`**: EventLogger, only present while debugging **Notes** -N/A +None ### Infrastructure ([infrastructure.hpp](include/infrastructure.hpp), [infrastructure.cpp](src/infrastructure.cpp)) **Description** @@ -579,53 +596,53 @@ Creates and stores the SDL and OpenGL infrastructures (window, renderer, context - **`SDL_Window* window() const`** - Description: Return the window - - Preconditions: N/A + - Preconditions: None - Postconditions: The window is returned - - Notes: N/A + - Notes: None - **`SDL_Renderer* renderer() const`** - Description: Return the renderer - - Preconditions: N/A + - Preconditions: None - Postconditions: The renderer is returned - - Notes: N/A + - Notes: None - **`SDL_Context context() const`** - Description: Return the context - - Preconditions: N/A + - Preconditions: None - Postconditions: The context is returned - - Notes: N/A + - Notes: None - **`bool init(const std::string name, const int width, const int height)`** - Description: Initialize everything - Preconditions: `name` is the window name, `width` and `height` are width and height of the window in pixels - Postconditions: An OpenGL context has been created and connected to the `SDL_Window`. The OpenGL functions have been loaded via glad. - - Notes: N/A + - Notes: None - **`void destroy()`** - Description: Destruct all resources - - Preconditions: N/A + - Preconditions: None - Postconditions: All resources have been destroyed - - Notes: N/A + - Notes: None - **`void quit()`** - Description: Quit the application - - Preconditions: N/A + - Preconditions: None - Postconditions: All resources have been destroyed and the application has quit - - Notes: N/A + - Notes: None **Private Function Members** -N/A +None **Public Data Members** -N/A +None **Private Data Members** -- `SDL_Window* window_`: Window -- `SDL_Renderer* renderer_`: Renderer -- `SDL_Context context_`: Context +- **`SDL_Window* window_`**: Window +- **`SDL_Renderer* renderer_`**: Renderer +- **`SDL_Context context_`**: Context **Notes** -N/A +None ### InputHandler ([input_handler.hpp](include/input_handler.hpp), [input_handler.cpp](src/input_handler.cpp)) **Description** @@ -645,25 +662,25 @@ Reads all input from SDL, preprocesses it and stores it in the `Toolbox` event c - **`void update(Toolbox& tb)`** - Description: Collect all current SDL events and store them as `Pevent`s in the toolbox `events` - - Preconditions: N/A + - Preconditions: None - Postconditions: The toolbox `events` have been updated - - Notes: N/A + - Notes: None **Private Function Members** -N/A +None **Public Data Members** -N/A +None **Private Data Members** -N/A +None **Notes** -N/A +None ### Message ([message.hpp](include/message.hpp), [message.cpp](src/message.cpp)) **Description** @@ -702,21 +719,21 @@ if(m.target == MESSAGETARGET::WAVE){ **Public Function Members** -N/A +None **Private Function Members** -N/A +None **Public Data Members** -- `MESSAGETARGET target` -- `std::variant<BLOCKCHAINMESSAGE, DRAWERMESSAGE, GUIMESSAGE, WAVEMESSAGE, PATTERNMESSAGE> message` -- `bool handled` +- **`MESSAGETARGET target`**: Target recipient of the message +- **`std::variant<BLOCKCHAINMESSAGE, DRAWERMESSAGE, GUIMESSAGE, WAVEMESSAGE, PATTERNMESSAGE> message`**: Content of the message +- **`bool handled`**: Has the message been handled yet? **Private Data Members** -N/A +None **Notes** @@ -745,7 +762,7 @@ Handles the placement of predefined patterns. - Description: Checks the mailbox, and upon requests draws the desired structure into the static damping texture - Preconditions: Correctly constructed object - Postconditions: All messages concerning patterns have been handled - - Notes: N/A + - Notes: None **Private Function Members** @@ -753,19 +770,19 @@ Handles the placement of predefined patterns. - Description: Load a damping texture from file, upload it to the GPU and return the texture handler in the `GLuint` out argument. - Preconditions: `file` is the texture file without extension, `texture_target` is an out argument - Postconditions: The texture has been uploaded to the GPU and has handler `texture_target` - - Notes: N/A + - Notes: None **Public Data Members** -N/A +None **Private Data Members** -- `GLuint texture_*_` +- **`GLuint texture_*_`**: Handlers to the predefined damping profile textures **Notes** -N/A +None ### Pevent ([pevent.hpp](include/pevent.hpp), [pevent.cpp](src/pevent.cpp)) **Description** @@ -783,23 +800,23 @@ Stores `SDL_Event`s in a more convenient way. **Public Function Members** -N/A +None **Private Function Members** -N/A +None **Public Data Members** -- `SDL_Event event` -- `unsigned itcoord_x, itcoord_y` -- `float fscoord_x, fscoord_y` -- `PEVENTTYPE type` -- `SDL_FingerID finger_id` +- **`SDL_Event event`**: The underlying `SDL_Event` +- **`unsigned itcoord_x, itcoord_y`**: Integer coordinates (in texels) with respect to full textures +- **`float fscoord_x, fscoord_y`**: Floating point coordinates with respect to the screen +- **`PEVENTTYPE type`**: Type of the `Pevent` +- **`SDL_FingerID finger_id`**: ID of the finger that generated this event **Private Data Members** -N/A +None **Notes** @@ -825,27 +842,27 @@ Constructs `Pevent` objects. - **`Pevent operator()(const SDL_Event&) const`** - Description: Generate a `Pevent` from and `SDL_Event` - - Preconditions: N/A + - Preconditions: None - Postconditions: Returns a `Pevent` that corresponds to the `SDL_Event` passed as argument. - - Notes: N/A + - Notes: None **Private Function Members** -N/A +None **Public Data Members** -N/A +None **Private Data Members** -- `int screen_w_, screen_h_`: screen width and height in pixels -- `int texture_w_, texture_h_`: texture width and height in texels -- `int texoffset_left_, texoffset_right_, texoffset_bottom_, texoffset_top_`: screen offsets in the texture (buffer sizes) +- **`int screen_w_, screen_h_`**: screen width and height in pixels +- **`int texture_w_, texture_h_`**: texture width and height in texels +- **`int texoffset_left_, texoffset_right_, texoffset_bottom_, texoffset_top_`**: screen offsets in the texture (buffer sizes) **Notes** -N/A +None ### Shader ([shader.hpp](include/shader.hpp), [shader.cpp](src/shader.cpp)) **Description** @@ -874,65 +891,65 @@ Shader stepshader((shader_path_ + "stepwave.vert").c_str(), (shader_path_ + "ste - **`void clean_up()`** - Description: Clean up the OpenGL resources associated with this shader - - Preconditions: N/A - - Postconditions: N/A - - Notes: N/A + - Preconditions: None + - Postconditions: None + - Notes: None - **`void use()`** - Description: Activates the shader - Preconditions: Correctly constructed object - Postconditions: The shader program is used - - Notes: N/A + - Notes: None - **`void setBool(const std::string& name, bool value) const`** - Description: Set a boolean uniform - Preconditions: `name` is the name of the target uniform, `value` the target value. - Postconditions: The target uniform has been set to `value` - - Notes: N/A + - Notes: None - **`void setInt(const std::string& name, int value) const`** - Description: Set an integer uniform - Preconditions: `name` is the name of the target uniform, `value` the target value. - Postconditions: The target uniform has been set to `value` - - Notes: N/A + - Notes: None - **`void setFloat(const std::string& name, float value) const`** - Description: Set a float uniform - Preconditions: `name` is the name of the target uniform, `value` the target value. - Postconditions: The target uniform has been set to `value` - - Notes: N/A + - Notes: None - **`void setVec2(const std::string& name, glm::vec2 value) const`** - Description: Set a vec2 uniform - Preconditions: `name` is the name of the target uniform, `value` the target value. - Postconditions: The target uniform has been set to `value` - - Notes: N/A + - Notes: None - **`void setVec3(const std::string& name, glm::vec3 value) const`** - Description: Set a vec3 uniform - Preconditions: `name` is the name of the target uniform, `value` the target value. - Postconditions: The target uniform has been set to `value` - - Notes: N/A + - Notes: None - **`void setVec4(const std::string& name, glm::vec4 value) const`** - Description: Set a vec4 uniform - Preconditions: `name` is the name of the target uniform, `value` the target value. - Postconditions: The target uniform has been set to `value` - - Notes: N/A + - Notes: None - **`void setMat(const std::string& name, glm::mat4 value) const`** - Description: Set a mat4 uniform - Preconditions: `name` is the name of the target uniform, `value` the target value. - Postconditions: The target uniform has been set to `value` - - Notes: N/A + - Notes: None **Private Function Members** -N/A +None **Public Data Members** -- `unsigned int ID`: OpenGL handle of the shader program +- **`unsigned int ID`**: OpenGL handle of the shader program **Private Data Members** -N/A +None **Notes** -N/A +None ### SlimBlockchainHandler ([slim_blockchain_handler.hpp](include/slim_blockchain_handler.hpp), [slim_blockchain_handler.cpp](src/slim_blockchain_handler.cpp)) **Description** @@ -956,59 +973,59 @@ The drawcalls are issued at the very end of the update-cycle, all in one. - Description: Update the toolbox - first handle messages, then handle events, update erase-/drawlists (dynamic and static) and finally draw the updated state to the dynamic damping and wave 1 textures. - Preconditions: Fully initialized object - Postconditions: The state has been updated and drawn to the necessary textures - - Notes: N/A + - Notes: None - **`size_t num_blocks()`** - Description: Get the current number of active blocks - - Preconditions: N/A + - Preconditions: None - Postconditions: The number of blocks is returned - - Notes: N/A + - Notes: None **Private Function Members** - **`void clear_blocks_()`** - Description: Erases all current blocks - - Preconditions: N/A + - Preconditions: None - Postconditions: All blocks have been erased, `dragpairs_` and `blockchain_` are empty - - Notes: N/A + - Notes: None - **`void update_blocks_(const Toolbox&, bool reload_all)`** - Description: Updates the state of the block tracking. First, the draw-/eraselists are checked for duplicated inputs (e.g. draw at R, erase at R, draw at R', erase at R', draw at R''). Then the vertices of blocks to be drawn / erased are calculated, and the queues are executed in the order: erase dynamic blocks, draw static blocks, draw dynamic blocks. - - Preconditions: N/A - - Postconditions: N/A - - Notes: N/A + - Preconditions: None + - Postconditions: All blocks have been updated (drawn / erased in the correct texture as requested) + - Notes: None - **`bool in_wave_window_(const Toolbox&, const Pevent&) const`** - Description: Check if a `Pevent` is within the wave window - - Preconditions: N/A + - Preconditions: None - Postconditions: Returns `true` if the passed `Pevent` is in the wave window, `false` else - - Notes: N/A + - Notes: None - **`void xywhs_to_vertices_(const Toolbox&, const std::vector<bool>& duplicates, const std::vector<glm::ivec4>& xywhs, std::vector<float>& vertices) const`** - Description: Calculate all vertices corresponding to the `EfficientBlock` `xywh` coordinates stored in `xywhs` and store them in `vertices`, while ignoring `xywhs[i]` if `duplicates[i] == true`. - - Preconditions: N/A + - Preconditions: None - Postconditions: The vertices corresponding to the non-duplicate marked `xywhs` coordinates have been calculated and are stored in `vertices`. Previous contents of `vertices` have been deleted. - Notes: If duplicates are not tracked (e.g. for static blocks, which can't be erased), pass `std::vector<bool>(xywhs.size(), false)` as `duplicates`. - **`void find_dynamic_duplicates_()`** - Description: Find duplicates in the dynamic draw-/eraselists and store them in the members `drawlist_dynamic_duplicates_` and `eraselist_dynamic_duplicates_`, respectively - - Preconditions: N/A + - Preconditions: None - Postconditions: The dynamic duplicate storing members have been updated according to the current dynamic draw-/eraselists - Notes: This takes care that one erase can only delete one draw. **Public Data Members** -N/A +None **Private Data Members** -- `int previous_mstate_`: The tb.mstate of the previous frame -- `std::list<EfficientBlock> blockchain_`: list of current `EfficientBlocks` -- `std::list<std::pair<EfficientBlock*, SDL_FingerID> > dragpairs_`: list of blocks and their controlling finger -- `Shader shader_drawblocks_`: Shader used to draw blocks -- `GLuint vao_, vbo_`: OpenGL infrastructure, vertex array object and vertex buffer object -- `GLuint fbo_wave_, fbo_dynamic_, fbo_static_`: framebuffer objects targeting the wave 1 texture, the dynamic damping texture, and the static damping texture, respectively -- `std::vector<glm::ivec4> drawlist_static_`: xywh coordinates of blocks to be drawn to the static damping texture -- `std::vector<glm::ivec4> drawlist_dynamic_`: xywh coordinates of blocks to be drawn to the dynamic damping texture -- `std::vector<glm::ivec4> eraselist_dynamic_`: xywh coordinates of blocks to be erased from the dynamic damping texture -- `std::vector<bool> drawlist_dynamic_duplicates_`: marks which indices of the dynamic drawlist are duplicates (i.e. paired with an entry of the dynamic eraselist) -- `std::vector<bool> eraselist_dynamic_duplicates_`: marks which indices of the dynamic eraselist are duplicates (i.e. paired with an entry of the dynamic drawlist) +- **`int previous_mstate_`**: The tb.mstate of the previous frame +- **`std::list<EfficientBlock> blockchain_`**: list of current `EfficientBlocks` +- **`std::list<std::pair<EfficientBlock*, SDL_FingerID> > dragpairs_`**: list of blocks and their controlling finger +- **`Shader shader_drawblocks_`**: Shader used to draw blocks +- **`GLuint vao_, vbo_`**: OpenGL infrastructure, vertex array object and vertex buffer object +- **`GLuint fbo_wave_, fbo_dynamic_, fbo_static_`**: framebuffer objects targeting the wave 1 texture, the dynamic damping texture, and the static damping texture, respectively +- **`std::vector<glm::ivec4> drawlist_static_`**: xywh coordinates of blocks to be drawn to the static damping texture +- **`std::vector<glm::ivec4> drawlist_dynamic_`**: xywh coordinates of blocks to be drawn to the dynamic damping texture +- **`std::vector<glm::ivec4> eraselist_dynamic_`**: xywh coordinates of blocks to be erased from the dynamic damping texture +- **`std::vector<bool> drawlist_dynamic_duplicates_`**: marks which indices of the dynamic drawlist are duplicates (i.e. paired with an entry of the dynamic eraselist) +- **`std::vector<bool> eraselist_dynamic_duplicates_`**: marks which indices of the dynamic eraselist are duplicates (i.e. paired with an entry of the dynamic drawlist) **Notes** @@ -1035,26 +1052,26 @@ Keeps track of the time since the last user input, and resets the state of the a - **`void update(Toolbox& tb)`** - Description: Check how much time has passed since an event has last come in, and if it exceeds the timeout, post reset messages and reset the timer. - - Preconditions: N/A + - Preconditions: None - Postconditions: If the timer exceeds the timeout, a reset has been posted. If `tb.events` is not empty or the timer has exceeded the timeout, the timer has been reset. - Notes: The reset messages need to be adjusted if more components are added. Potentially, one could add a messagetarget `ALL`, with a message `RESET` everyone listens to. **Private Function Members** -N/A +None **Public Data Members** -N/A +None **Private Data Members** -- `int seconds_to_timeout_`: Number of seconds that constitute a timeout -- `std::chrono::time_point<std::chrono::high_resolution_clock> time_last_input_`: Time of last user input +- **`int seconds_to_timeout_`**: Number of seconds that constitute a timeout +- **`std::chrono::time_point<std::chrono::high_resolution_clock> time_last_input_`**: Time of last user input **Notes** -N/A +None ### Toolbox ([toolbox.hpp](include/toolbox.hpp), [toolbox.cpp](src/toolbox.cpp)) **Description** @@ -1076,21 +1093,58 @@ The Toolbox is passed from one component to the next, so each component has all - **`void newFrame()`** - Description: Start a new frame - - Preconditions: N/A + - Preconditions: None - Postconditions: `mailbox` and `events` have been cleared - Notes: Call this function at the very beginning of each frame **Private Function Members** -N/A +None **Public Data Members** -Check the source, there are ~50 members and they are well documented. +- **`GLuint tex_damp_dynamic`**: Handle to the dynamic damping texture +- **`GLuint tex_damp_static`**: Handle to the static damping texture +- **`GLuint tex_wave_clean`**: Handle to a texture that contains the vanilla (initial) wave profile +- **`GLuint tex_damp_clean`**: Handle to a texture that contains the vanilla (initial) damping profile +- **`GLuint tex_const_zero`**: Handle to a texture that contains only zeros +- **`GLuint tex_wave_0, tex_wave_1`**: Handle to the simulational wave textures 0 and 1 + - Note: To influence the wave, any non-`WaveHandler` module should always draw to `tex_wave_1` +- **`std::vector<Message> mailbox`**: Mailbox that stores messages that have been posted +- **`std::list<Pevent> events`**: Event list that stores the current user input events +- **`PeventFactory pevFactory`**: Factory to generate `Pevent`s from `SDL_Event`s; used by `InputHandler` +- **`Infrastructure infra`**: Stores all OpenGL and SDL infrastructure +- **`int m_state`**: Current mouse state (integer cast from `MSTATE`) +- **`int s_state`**: Current source state (integer cast from `SSTATE`) +- **`int g_state`**: Current game state (integer cast from `GSTATE`) +- **`int block_width`**: Width of blocks placed by SlimBlockchainHandler +- **`int block_height`**: Height of blocks placed by SlimBlockchainHandler +- **`float source_amplitude`**: Amplitude of wave sources +- **`float source_frequency`**: Frequency of wave sources +- **`int screen_w`**: Width of displaying screen in pixels +- **`int screen_h`**: Height of displaying screen in pixels +- **`int texture_w`**: Width of damping / wave textures in texels +- **`int texture_h`**: Height of damping / wave textures in texels +- **`float gui_pos`**: Horizontal fraction of the screen occupied by the GUI +- **`const int texoffset_left, texoffset_right`**: Offset of the screen from left and right texture boundaries in texels +- **`const int texoffset_bottom, texoffset_top`**: Offset of the screen from bottom and top texture boundaries in texels +- **`std::string shader_path`**: Path to the folder containing shader sources +- **`std::string texture_path`**: Path to the folder containing damping textures +- **`std::string resource_path`**: Path to the folder containing resources ("ft_top") +- **`float time`**: Current simulation time +- **`float dt`**: Simulation timestep +- **`int drawing_width`**: Strokewidth in texels when drawing with `Drawer` (see `Drawer::calculate_points_`) +- **`int erasing_width`**: Strokewidth in texels when erasing with `Drawer` (see `Drawer::calculate_points_`) +- **`size_t num_blocks`**: Number of `EfficientBlock`s currently controlled by `SlimBlockchainHandler` +- **`size_t num_drawers`**: Number of `Drawer`s currently controlled by `DrawingHandler` +- **`int timeout_threshold`**: Number of seconds that constitute a timeout +- **`int timeout_timer`**: Current timeout timer in seconds +- **`SDL_TouchID touch_device`**: ID of the connected touch device (read: touchscreen) +- **`std::vector<SDL_FingerID> current_touchIDs`**: IDs of all fingers that are currently touching the touch device **Private Data Members** -N/A +None **Notes** @@ -1121,47 +1175,47 @@ Handles simulation and rendering of the wave. - **`bool initialize(const std::string damping_file, const std::string palette_file)`** - Description: Fully initialize the object (especially shaders, textures, framebuffers and other OpenGL infrastructure) - - Preconditions: N/A + - Preconditions: None - Postconditions: The object is fully initialized - Notes: Without a call to this function, the object is not functional. - **`void update(Toolbox&)`** - Description: Handle all messages addressed to this object - - Preconditions: N/A + - Preconditions: None - Postconditions: All relevant messages have been handled - - Notes: N/A + - Notes: None - **`void prepare_step()`** - Description: Prepare for timestepping by combining the dynamic and static damping textures into one texture. - - Preconditions: N/A + - Preconditions: None - Postconditions: The texture `tex_comp_damp_` has been updated - - Notes: N/A + - Notes: None - **`bool step(Toolbox& tb, const int num_dsteps)`** - Description: Perform `num_dsteps` double-timesteps on the wave - - Preconditions: N/A + - Preconditions: None - Postconditions: 2*`num_dsteps` timesteps have been performed and the latest step is stored in `tex_comp_wave_1_`. - Notes: Always returns `true` - **`bool render()`** - Description: Render `tex_comp_damp_` and `tex_wave_1_` using the color scheme `tex_palette_` to the current screenbuffer using shader `shdr_2d_` - - Preconditions: N/A + - Preconditions: None - Postconditions: The state has been rendered - Notes: Always returns `true` - **`GLuint get_damping_tex() const`** - Description: Get the combined damping texture - - Preconditions: N/A + - Preconditions: None - Postconditions: The combined damping texture handler is returned - - Notes: N/A + - Notes: None - **`unsigned get_width() const`** - Description: Get the window width - - Preconditions: N/A + - Preconditions: None - Postconditions: The window width is returned - - Notes: N/A + - Notes: None - **`unsigned get_height() const`** - Description: Get the window height - - Preconditions: N/A + - Preconditions: None - Postconditions: The window height is returned - - Notes: N/A + - Notes: None - **`void generate_and_transfer_textures(Toolbox&)`** - Description: Generate textures and transfer these and existing textures to the `Toolbox`. - - Preconditions: N/A + - Preconditions: None - Postconditions: Three textures have been generated and initialized correctly: `tb.tex_damp_clean`, `tb.tex_wave_clean`, `tb.tex_const_zero`. Four textures have been transferred to the `Toolbox`: `tex_comp_damp_dynamic_`, `tex_comp_damp_static_`, `tex_comp_wave_0_`, `tex_comp_wave_1_` - Notes: This function has to be called to fully initialize the `Toolbox` @@ -1170,14 +1224,11 @@ Handles simulation and rendering of the wave. - **`bool initialize_2D_data_()`** - Description: Initialize OpenGL infrastructure to perform timesteps - - Preconditions: N/A + - Preconditions: None - Postconditions: The objects `num_elements_2d`, `vao_2d_`, `vbo_2d_`, `ebo_2d_` have been initialized - - Notes: N/A + - Notes: None - **`bool initialize_3D_data_()`** - Description: Do not call - - Preconditions: N/A - - Postconditions: N/A - - Notes: N/A - **`bool initialize_comp_data_(const std::string)`** - Description: Initialize damping and wave textures, and time stepping framebuffers - Preconditions: The argument specifies the damping file, without extension. @@ -1194,7 +1245,7 @@ Handles simulation and rendering of the wave. - Notes: Always returns `true`, except when the colour palette file is invalid. - **`bool initialize_shaders_()`** - Description: Initialize all shaders - - Preconditions: N/A + - Preconditions: None - Postconditions: The following shaders have been initialized from source: `shdr_step_`(stepwave), `shdr_2d_`(render2d), `shdr_2d_dbg_`(render2d), `shdr_damp_`(combine_damping) and their uniforms have been set - Notes: Always returns `true` - **`bool load_damping_(const std::string)`** @@ -1211,25 +1262,25 @@ Handles simulation and rendering of the wave. **Public Data Members** -N/A +None **Private Data Members** Only relevant members are listed -- `const int width_, height_`: Window dimensions -- `const int texwidth_, texheight_`: Texture dimensions -- `const int texoffset_left_, texoffset_right_, texoffset_bottom_, texoffset_top_`: Offsets in pixels in textures from the screen -- `const std::string shader_path_`: Path to shaders -- `GLuint vbo_2d_, vao_2d_, ebo_2d_, num_elements_2d_`: Timestepping OpenGL infrastructure -- `GLuint vbo_render_, vao_render_, ebo_render_, num_elements_render_`: Rendering OpenGL infrastructure -- `GLuint fb_comp_0_, fb_comp_1_, fb_comp_damp_`: Framebuffers targeting wave texture 0 `tex_comp_wave_0_`, wave texture 1 `tex_comp_wave_1_` and the combined damping texture `tex_comp_damp_`, respectively. -- `GLuint tex_comp_wave_0_, tex_comp_wave_1_`: Wave textures 0 and 1, between which timestepping happens. The latest state is always in `tex_comp_wave_1_`, and the first step of a chain goes from 1 to 0. -- `GLuint tex_comp_damp_`: Combined damping texture -- `GLuint tex_comp_damp_dynamic_, tex_comp_damp_static_`: Dynamic damping texture (for obstacles that are dynamic like "Spielen" blocks) and static damping texture (for static obstacles like drawings and predefined structures) -- `std::vector<float> palette_`: colour palette texture data -- `GLuint tex_palette_`: Colour palette texture handle -- `Shader shdr_step_, shdr_2d_, shdr_2d_dbg_, shdr_damp_`: Shaders used for timestepping, rendering (without and with debugging) and damping combination -- `std::vector<float> tex_wave_data_, tex_damp_data_`: The vanilla wave and damping texture data +- **`const int width_, height_`**: Window dimensions +- **`const int texwidth_, texheight_`**: Texture dimensions +- **`const int texoffset_left_, texoffset_right_, texoffset_bottom_, texoffset_top_`**: Offsets in pixels in textures from the screen +- **`const std::string shader_path_`**: Path to shaders +- **`GLuint vbo_2d_, vao_2d_, ebo_2d_, num_elements_2d_`**: Timestepping OpenGL infrastructure +- **`GLuint vbo_render_, vao_render_, ebo_render_, num_elements_render_`**: Rendering OpenGL infrastructure +- **`GLuint fb_comp_0_, fb_comp_1_, fb_comp_damp_`**: Framebuffers targeting wave texture 0 `tex_comp_wave_0_`, wave texture 1 `tex_comp_wave_1_` and the combined damping texture `tex_comp_damp_`, respectively. +- **`GLuint tex_comp_wave_0_, tex_comp_wave_1_`**: Wave textures 0 and 1, between which timestepping happens. The latest state is always in `tex_comp_wave_1_`, and the first step of a chain goes from 1 to 0. +- **`GLuint tex_comp_damp_`**: Combined damping texture +- **`GLuint tex_comp_damp_dynamic_, tex_comp_damp_static_`**: Dynamic damping texture (for obstacles that are dynamic like "Spielen" blocks) and static damping texture (for static obstacles like drawings and predefined structures) +- **`std::vector<float> palette_`**: colour palette texture data +- **`GLuint tex_palette_`**: Colour palette texture handle +- **`Shader shdr_step_, shdr_2d_, shdr_2d_dbg_, shdr_damp_`**: Shaders used for timestepping, rendering (without and with debugging) and damping combination +- **`std::vector<float> tex_wave_data_, tex_damp_data_`**: The vanilla wave and damping texture data **Notes** @@ -1258,13 +1309,13 @@ This class predates the Toolbox and is not yet well integrated into the flow. Al **`DRAWERMESSAGE`**: `CLEAR` -**`GUIMESSAGE`**: n/a +**`GUIMESSAGE`**: None **`WAVEMESSAGE`**: `RESET_WAVE`, `RESET_DAMPING`, `DIMENSION_2D`, `DIMENSION_3D`, `DEBUG_ON`, `DEBUG_OFF` ### Pevent Types -**`PEVENTTYPE`** (Possible `Pevent` types): `DOWN`, `UP`, `MOVE`, `OTHER` +**`PEVENTTYPE`**: `DOWN`, `UP`, `MOVE`, `OTHER` ## ImGui Customization The ImGui library has been customized in the following way: