diff --git a/0.4/PTM.vcxproj b/0.4/PTM.vcxproj index f7274e8..41923d5 100644 --- a/0.4/PTM.vcxproj +++ b/0.4/PTM.vcxproj @@ -32,6 +32,7 @@ + @@ -82,6 +83,7 @@ + diff --git a/0.4/PTM.vcxproj.filters b/0.4/PTM.vcxproj.filters index f75fef8..016c228 100644 --- a/0.4/PTM.vcxproj.filters +++ b/0.4/PTM.vcxproj.filters @@ -56,9 +56,6 @@ GRAPHICS - CORE - - CORE - RUNTIME UTILITIES @@ -128,6 +125,12 @@ GRAPHICS - CORE + + EDITOR + + + EDITOR + @@ -196,9 +199,6 @@ GRAPHICS - CORE - - CORE - UTIL @@ -304,6 +304,12 @@ GRAPHICS - CORE + + EDITOR + + + EDITOR + @@ -339,5 +345,8 @@ {d73b4aac-b700-424b-8ae1-15ba947d5ef1} + + {a7b7ca7a-6d73-42da-885c-4b9bfc3e8753} + \ No newline at end of file diff --git a/0.4/build/PTM.exe b/0.4/build/PTM.exe index bc1d536..c27feb1 100644 Binary files a/0.4/build/PTM.exe and b/0.4/build/PTM.exe differ diff --git a/0.4/build/root/CHARSET b/0.4/build/root/CHARSET index bb008f1..62a3453 100644 --- a/0.4/build/root/CHARSET +++ b/0.4/build/root/CHARSET @@ -1,36 +1,37 @@ -AUTOREF 0 -CLS -SET ix,1 -SET iy,1 -SET c,0 -RTILE -TILE 0,15,0 -:loop -LOCATE ix,iy -CSET 0,c -PUT -INC c -INC ix -GOTO.LE ix,16,loop -INC iy -SET ix,1 -GOTO.LE iy,16,loop -SET ix,1 -SET iy,0 -SET ch,0 -:loop2 -LOCATE ix,iy -PRINTF "%X",ch -INC ix -INC ch -GOTO.LE ix,16,loop2 -SET ix,0 -SET iy,1 -SET ch,0 -:loop3 -LOCATE ix,iy -PRINTF "%X",ch -INC iy -INC ch -GOTO.LE iy,16,loop3 -LOCATE 0,18 +main: + AUTOREF 0 + CLS + SET ix,1 + SET iy,1 + SET c,0 + RTILE + TILE 0,15,0 +loop: + LOCATE ix,iy + CSET 0,c + PUT + INC c + INC ix + GOTO.LE ix,16,loop + INC iy + SET ix,1 + GOTO.LE iy,16,loop + SET ix,1 + SET iy,0 + SET ch,0 +loop2: + LOCATE ix,iy + PRINTF "%X",ch + INC ix + INC ch + GOTO.LE ix,16,loop2 + SET ix,0 + SET iy,1 + SET ch,0 +loop3: + LOCATE ix,iy + PRINTF "%X",ch + INC iy + INC ch + GOTO.LE iy,16,loop3 + LOCATE 0,18 diff --git a/0.4/build/root/PALETTE b/0.4/build/root/PALETTE index f41c1a1..bc649a2 100644 --- a/0.4/build/root/PALETTE +++ b/0.4/build/root/PALETTE @@ -1,36 +1,38 @@ -AUTOREF 0 -CLS -SET ix,1 -SET iy,1 -SET c,0 -RTILE -TILE 0,0,0 -:loop -LOCATE ix,iy -BSET 0,c -PUT -INC c -INC ix -GOTO.LE ix,16,loop -INC iy -SET ix,1 -GOTO.LE iy,16,loop -SET ix,1 -SET iy,0 -SET ch,0 -:loop2 -LOCATE ix,iy -PRINTF "%X",ch -INC ix -INC ch -GOTO.LE ix,16,loop2 -SET ix,0 -SET iy,1 -SET ch,0 -:loop3 -LOCATE ix,iy -PRINTF "%X",ch -INC iy -INC ch -GOTO.LE iy,16,loop3 -LOCATE 0,18 +main: + AUTOREF 0 + CLS + SET ix,1 + SET iy,1 + SET c,0 + RTILE + TILE 0,0,0 + +loop: + LOCATE ix,iy + BSET 0,c + PUT + INC c + INC ix + GOTO.LE ix,16,loop + INC iy + SET ix,1 + GOTO.LE iy,16,loop + SET ix,1 + SET iy,0 + SET ch,0 +loop2: + LOCATE ix,iy + PRINTF "%X",ch + INC ix + INC ch + GOTO.LE ix,16,loop2 + SET ix,0 + SET iy,1 + SET ch,0 +loop3: + LOCATE ix,iy + PRINTF "%X",ch + INC iy + INC ch + GOTO.LE iy,16,loop3 + LOCATE 0,18 diff --git a/0.4/build/root/TEST_GAME_1 b/0.4/build/root/TEST_GAME_1 new file mode 100644 index 0000000..1baf760 --- /dev/null +++ b/0.4/build/root/TEST_GAME_1 @@ -0,0 +1,4 @@ +main: + CURSOR 0 + PRINT "Hello World 123!" + HALT diff --git a/0.4/src/PTM.cpp b/0.4/src/PTM.cpp index 0a0c0eb..83de3dd 100644 --- a/0.4/src/PTM.cpp +++ b/0.4/src/PTM.cpp @@ -14,11 +14,13 @@ #include "t_program.h" #include "t_program_line.h" #include "t_program_runner.h" +#include "t_program_editor.h" #include "t_filesystem.h" int wnd_size = 3; t_window wnd; t_main_editor main_editor; +t_program_editor program_editor; t_interpreter intp; t_program prg; t_program_runner prg_runner; @@ -64,16 +66,21 @@ void PTM::init() scr.set_palette(&pal); intp.init(this, &scr, &kb); + program_editor.init(this, &scr, &kb); main_editor.init(this, &scr, &kb, &intp); + + main_editor.active = true; + program_editor.active = false; } void PTM::run_main() { - snd.alert(); - bool autoexec = t_filesystem::file_exists(autoexec_file); - if (!autoexec) + + if (!autoexec) { + snd.alert(); main_editor.print_welcome(true); + } while (wnd.is_open()) { if (autoexec) { @@ -110,6 +117,7 @@ void PTM::reset() new_program(); main_editor.reset(); main_editor.print_welcome(false); + program_editor.reset(); } void PTM::pause(int frames) @@ -139,6 +147,9 @@ void PTM::on_machine_cycle() if (!wnd.is_open()) return; + if (program_editor.active) + program_editor.draw_program(); + if (auto_screen_update) refresh_screen(); @@ -158,7 +169,10 @@ void PTM::on_machine_cycle() else if (!kb.alt() && !halted) { kb.push_key(key); if (!prg_runner.is_running()) { - main_editor.on_keydown(); + if (main_editor.active) + main_editor.on_keydown(); + if (program_editor.active) + program_editor.on_keydown(); } } } @@ -166,6 +180,9 @@ void PTM::on_machine_cycle() void PTM::on_escape_key_pressed() { + if (!enable_user_break) + return; + if (halted) { halted = false; } diff --git a/0.4/src/PTM.h b/0.4/src/PTM.h index 71d1574..3148d50 100644 --- a/0.4/src/PTM.h +++ b/0.4/src/PTM.h @@ -32,6 +32,7 @@ class PTM t_tile tilereg; bool auto_screen_update = true; + bool enable_user_break = true; void run(); void exit(); diff --git a/0.4/src/PTML_ALL.cpp b/0.4/src/PTML_ALL.cpp index d703cde..f58ca79 100644 --- a/0.4/src/PTML_ALL.cpp +++ b/0.4/src/PTML_ALL.cpp @@ -26,6 +26,7 @@ t_function_ptr PTML::get_cmd_pointer(const t_string& cmd) CMD("EXIT", EXIT); CMD("RESET", RESET); CMD("PAUSE", PAUSE); + CMD("BREAK", BREAK); // === MEMORY === CMD("SET", SET); diff --git a/0.4/src/PTML_CTFLOW.cpp b/0.4/src/PTML_CTFLOW.cpp index 5be84ed..70b40cc 100644 --- a/0.4/src/PTML_CTFLOW.cpp +++ b/0.4/src/PTML_CTFLOW.cpp @@ -129,3 +129,9 @@ void PTML::PAUSE() ARGC(1); ptm->pause(NUM(1)); } + +void PTML::BREAK() +{ + ARGC(1); + ptm->enable_user_break = BOOL(1); +} diff --git a/0.4/src/PTML_CTFLOW.h b/0.4/src/PTML_CTFLOW.h index 2c170d5..43c5d70 100644 --- a/0.4/src/PTML_CTFLOW.h +++ b/0.4/src/PTML_CTFLOW.h @@ -26,4 +26,5 @@ namespace PTML void CALL_IFNKEY(); void RET(); void PAUSE(); + void BREAK(); } diff --git a/0.4/src/t_main_editor.cpp b/0.4/src/t_main_editor.cpp index 200e1b4..c86ac61 100644 --- a/0.4/src/t_main_editor.cpp +++ b/0.4/src/t_main_editor.cpp @@ -46,6 +46,9 @@ void t_main_editor::reset() void t_main_editor::print_welcome(bool show_prompt) { + if (!active) + return; + scr->print_string_crlf(ptm->version_string); scr->print_string_crlf(ptm->title_short); scr->print_string_crlf(ptm->copyright_notice); diff --git a/0.4/src/t_main_editor.h b/0.4/src/t_main_editor.h index e008837..4809550 100644 --- a/0.4/src/t_main_editor.h +++ b/0.4/src/t_main_editor.h @@ -12,6 +12,8 @@ class t_sound; class t_main_editor { public: + bool active = true; + t_dict function_keys; t_dict function_keys_shifted; diff --git a/0.4/src/t_program_editor.cpp b/0.4/src/t_program_editor.cpp new file mode 100644 index 0000000..ccdeb07 --- /dev/null +++ b/0.4/src/t_program_editor.cpp @@ -0,0 +1,109 @@ +#include "t_program_editor.h" +#include "PTM.h" +#include "t_tile.h" +#include "t_screen.h" +#include "t_keyboard.h" +#include "t_util.h" +#include "predefined_charset_ix.h" + +t_program_editor::t_program_editor() +{ +} + +t_program_editor::~t_program_editor() +{ +} + +void t_program_editor::init(PTM* ptm, t_screen* scr, t_keyboard* kb) +{ + this->ptm = ptm; + this->scr = scr; + this->kb = kb; + this->snd = &ptm->get_sound(); + + first_line_ix = 0; + last_line_ix = scr->last_row; +} + +void t_program_editor::reset() +{ +} + +void t_program_editor::draw_program() +{ + for (int i = first_line_ix; i <= last_line_ix; i++) { + if (i >= 0 && i < lines.size()) + scr->print_string_crlf(lines[i]); + else + break; + } +} + +void t_program_editor::on_keydown() +{ + SDL_Keycode key = kb->peek_key(); + + switch (key) + { + case SDLK_RIGHT: { + kb->ctrl() ? + scr->move_cursor_next_logical_x(1) : + scr->move_cursor_dist(1, 0); + break; + } + case SDLK_LEFT: { + kb->ctrl() ? + scr->move_cursor_next_logical_x(-1) : + scr->move_cursor_dist(-1, 0); + break; + } + case SDLK_HOME: { + scr->move_cursor_line_start(); + break; + } + case SDLK_END: { + scr->move_cursor_eol(); + break; + } + case SDLK_BACKSPACE: { + scr->on_backspace_pressed(); + break; + } + case SDLK_DELETE: { + scr->on_delete_pressed(); + break; + } + case SDLK_TAB: { + for (int i = 0; i < 8; i++) + scr->on_character_key_pressed(predef_char.whitespace); + break; + } + case SDLK_INSERT: { + scr->toggle_insert_mode(); + break; + } + case SDLK_RETURN: { + on_enter_pressed(); + break; + } + case SDLK_q: { + if (kb->ctrl()) + ptm->exit(); + break; + } + default: { + unsigned char ch = kb->keycode_to_char(key); + if (ch > 0) { + scr->on_character_key_pressed(ch); + snd->keystroke(); + } + break; + } + } + + kb->pop_key(); +} + +void t_program_editor::on_enter_pressed() +{ +} diff --git a/0.4/src/t_program_editor.h b/0.4/src/t_program_editor.h new file mode 100644 index 0000000..72e4e2d --- /dev/null +++ b/0.4/src/t_program_editor.h @@ -0,0 +1,37 @@ +#pragma once +#include +#include "t_list.h" +#include "t_string.h" + +class PTM; +class t_screen; +class t_keyboard; +class t_interpreter; +class t_sound; + +class t_program_editor +{ +public: + bool active = false; + + t_program_editor(); + ~t_program_editor(); + + void init(PTM* ptm, t_screen* scr, t_keyboard* kb); + void reset(); + void on_keydown(); + void draw_program(); + +private: + PTM* ptm = nullptr; + t_screen* scr = nullptr; + t_keyboard* kb = nullptr; + t_sound* snd = nullptr; + + t_list lines; + int cur_line_ix = 0; + int first_line_ix = 0; + int last_line_ix = 0; + + void on_enter_pressed(); +}; diff --git a/0.4/src/t_tokenizer.cpp b/0.4/src/t_tokenizer.cpp index 8b07d5c..a57fc4f 100644 --- a/0.4/src/t_tokenizer.cpp +++ b/0.4/src/t_tokenizer.cpp @@ -136,8 +136,8 @@ t_token t_tokenizer::parse_token(int token_index, t_string& src) token.type = t_token_type::comment; } // ===== LABEL ===== - else if (src.starts_with(sym.label)) { - auto&& val = src.skip(1); + else if (src.ends_with(sym.label)) { + auto&& val = src.substr(0, src.length() - 2); if (val.empty()) { token.type = t_token_type::invalid; } diff --git a/0.4A/PTM.sln b/0.4A/PTM.sln deleted file mode 100644 index e6789ea..0000000 --- a/0.4A/PTM.sln +++ /dev/null @@ -1,28 +0,0 @@ - -Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 17 -VisualStudioVersion = 17.12.35514.174 d17.12 -MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "PTM", "PTM\PTM.vcxproj", "{D475CED4-54B8-4ABD-8E5F-E23325B6EB92}" -EndProject -Global - GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 - EndGlobalSection - GlobalSection(ProjectConfigurationPlatforms) = postSolution - {D475CED4-54B8-4ABD-8E5F-E23325B6EB92}.Debug|x64.ActiveCfg = Debug|x64 - {D475CED4-54B8-4ABD-8E5F-E23325B6EB92}.Debug|x64.Build.0 = Debug|x64 - {D475CED4-54B8-4ABD-8E5F-E23325B6EB92}.Debug|x86.ActiveCfg = Debug|Win32 - {D475CED4-54B8-4ABD-8E5F-E23325B6EB92}.Debug|x86.Build.0 = Debug|Win32 - {D475CED4-54B8-4ABD-8E5F-E23325B6EB92}.Release|x64.ActiveCfg = Release|x64 - {D475CED4-54B8-4ABD-8E5F-E23325B6EB92}.Release|x64.Build.0 = Release|x64 - {D475CED4-54B8-4ABD-8E5F-E23325B6EB92}.Release|x86.ActiveCfg = Release|Win32 - {D475CED4-54B8-4ABD-8E5F-E23325B6EB92}.Release|x86.Build.0 = Release|Win32 - EndGlobalSection - GlobalSection(SolutionProperties) = preSolution - HideSolutionNode = FALSE - EndGlobalSection -EndGlobal diff --git a/0.4A/PTM/PTM.vcxproj b/0.4A/PTM/PTM.vcxproj deleted file mode 100644 index fc624a8..0000000 --- a/0.4A/PTM/PTM.vcxproj +++ /dev/null @@ -1,194 +0,0 @@ - - - - - Debug - Win32 - - - Release - Win32 - - - Debug - x64 - - - Release - x64 - - - - 17.0 - Win32Proj - {d475ced4-54b8-4abd-8e5f-e23325b6eb92} - PTM - 10.0 - - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - Application - true - v143 - Unicode - - - Application - false - v143 - true - Unicode - - - - - - - - - - - - - - - - - - - - - $(SolutionDir)build\ - $(SolutionDir)temp\ - - - false - - - - Level3 - true - WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - - - - - Level3 - true - true - true - WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - Level1 - true - _CRT_SECURE_NO_WARNINGS;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - stdcpplatest - stdclatest - C:\Lib\SDL3-3.1.6\include;%(AdditionalIncludeDirectories) - MultiThreadedDebug - - - Windows - true - C:\Lib\SDL3-3.1.6\lib\x64;%(AdditionalLibraryDirectories) - SDL3.lib;%(AdditionalDependencies) - - - - - Level3 - true - true - true - NDEBUG;_CONSOLE;%(PreprocessorDefinitions) - true - - - Console - true - true - true - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/0.4A/PTM/PTM.vcxproj.filters b/0.4A/PTM/PTM.vcxproj.filters deleted file mode 100644 index 3ed3ff2..0000000 --- a/0.4A/PTM/PTM.vcxproj.filters +++ /dev/null @@ -1,163 +0,0 @@ - - - - - - UTIL - - - UTIL - - - CORE - - - UTIL - - - UTIL - - - GRAPHICS\BASIC - - - GRAPHICS\BASIC - - - GRAPHICS\BASIC - - - GRAPHICS\BASIC - - - GRAPHICS\BASIC - - - GRAPHICS\BASIC - - - GRAPHICS\COMPLEX - - - SUBSYSTEMS - - - INPUT - - - GRAPHICS\COMPLEX - - - UTIL - - - CORE - - - SUBSYSTEMS - - - INPUT - - - GRAPHICS\COMPLEX - - - - - UTIL - - - UTIL - - - CORE - - - UTIL - - - UTIL - - - UTIL - - - GRAPHICS\BASIC - - - GRAPHICS\BASIC - - - GRAPHICS\BASIC - - - GRAPHICS\BASIC - - - GRAPHICS\BASIC - - - GRAPHICS\BASIC - - - GRAPHICS\BASIC - - - GRAPHICS\BASIC - - - GRAPHICS\COMPLEX - - - INPUT - - - SUBSYSTEMS - - - GRAPHICS\COMPLEX - - - UTIL - - - CORE - - - SUBSYSTEMS - - - CORE - - - INPUT - - - GRAPHICS\COMPLEX - - - - - {a0a9d060-1925-44ba-b67c-1196e7eafd6f} - - - {4b4ffa97-998d-45d4-a96a-b2bf2e7862d5} - - - {08f6e765-5c0f-4eec-b762-c3fb209a89af} - - - {6df5a51a-5f83-417f-9207-70188839c395} - - - {45341c82-7cce-4697-a766-45472cdd5995} - - - {b5cf3d74-c85a-481a-95ed-a692781e9c2b} - - - {44342616-f519-4a53-b53a-8d5ea70946f1} - - - \ No newline at end of file diff --git a/0.4A/PTM/main.cpp b/0.4A/PTM/main.cpp deleted file mode 100644 index 1fbfc8d..0000000 --- a/0.4A/PTM/main.cpp +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "t_ptm.h" - -int main(int argc, char* argv[]) -{ - return ptm.sys.run(); -} diff --git a/0.4A/PTM/t_binary.h b/0.4A/PTM/t_binary.h deleted file mode 100644 index a6b3182..0000000 --- a/0.4A/PTM/t_binary.h +++ /dev/null @@ -1,4 +0,0 @@ -#pragma once -#include "t_string.h" - -using t_binary = t_string; diff --git a/0.4A/PTM/t_board.cpp b/0.4A/PTM/t_board.cpp deleted file mode 100644 index 7920dbc..0000000 --- a/0.4A/PTM/t_board.cpp +++ /dev/null @@ -1,50 +0,0 @@ -#include "t_board.h" - -t_board::t_board() -{ -} - -t_board::~t_board() -{ - for (int layer = 0; layer < layers; layer++) { - for (int i = 0; i < size; i++) { - tiles[layer].clear(); - } - } - - this->cols = 0; - this->rows = 0; - this->size = 0; -} - -void t_board::init(int cols, int rows) -{ - this->cols = cols; - this->rows = rows; - this->size = cols * rows; - - for (int layer = 0; layer < layers; layer++) { - for (int i = 0; i < size; i++) { - tiles[layer].emplace_back(); - } - } -} - -void t_board::set_tile(int layer, int x, int y, const t_tile& tile) -{ - tiles[layer][y * cols + x] = tile; -} - -t_tile& t_board::get_tile(int layer, int x, int y) -{ - return tiles[layer][y * cols + x]; -} - -void t_board::clear() -{ - for (int layer = 0; layer < layers; layer++) { - for (int i = 0; i < size; i++) { - tiles[layer][i].set_empty(); - } - } -} diff --git a/0.4A/PTM/t_board.h b/0.4A/PTM/t_board.h deleted file mode 100644 index aba6a72..0000000 --- a/0.4A/PTM/t_board.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include "t_tile.h" -#include "t_list.h" - -class t_board -{ -public: - t_board(); - ~t_board(); - - void init(int cols, int rows); - void set_tile(int layer, int x, int y, const t_tile& tile); - t_tile& get_tile(int layer, int x, int y); - void clear(); - -private: - static const int layers = 3; - - int cols = 0; - int rows = 0; - int size = 0; - - t_list tiles[layers]; -}; diff --git a/0.4A/PTM/t_charset.cpp b/0.4A/PTM/t_charset.cpp deleted file mode 100644 index f509665..0000000 --- a/0.4A/PTM/t_charset.cpp +++ /dev/null @@ -1,325 +0,0 @@ -#include "t_charset.h" - -t_charset::t_charset() -{ - reset(); -} - -t_charset::t_charset(const t_charset& other) -{ - copy_from(other); -} - -t_charset& t_charset::operator=(const t_charset& other) -{ - if (this == &other) - return *this; - - copy_from(other); - - return *this; -} - -void t_charset::copy_from(const t_charset& other) -{ - remove_all(); - for (int i = 0; i < other.chars.size(); i++) { - chars.emplace_back(other.chars[i]); - } -} - -void t_charset::remove_all() -{ - chars.clear(); -} - -void t_charset::add(const t_binary& bits) -{ - chars.emplace_back(bits); -} - -t_binary& t_charset::get(t_index index) -{ - return chars[index]; -} - -void t_charset::set(t_index index, const t_binary& bits) -{ - chars[index] = bits; -} - -void t_charset::set_row(t_index chr_index, t_index row, const t_binary& bits) -{ - auto rows = chars[chr_index].split_chunks(8); - rows[row] = bits.get_first(8); - chars[chr_index] = t_string::join(rows, ""); -} - -int t_charset::size() const -{ - return (int)chars.size(); -} - -void t_charset::reset() -{ - remove_all(); - - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - - add("0000000000000000000000000000000000000000000000000000000000000000"); // 32 Whitespace - add("0000000000011000000110000001100000011000000000000001100000000000"); // 33 - add("0000000001100110011001100110011000000000000000000000000000000000"); // 34 - add("0000000001100110111111110110011001100110111111110110011000000000"); // 35 - add("0001100000111110011000000011110000000110011111000001100000000000"); // 36 - add("0000000001100110011011000001100000110000011001100100011000000000"); // 37 - add("0001110000110110000111000011100001101111011001100011101100000000"); // 38 - add("0000000000011000000110000001100000000000000000000000000000000000"); // 39 - add("0000000000001110000111000001100000011000000111000000111000000000"); // 40 - add("0000000001110000001110000001100000011000001110000111000000000000"); // 41 - add("0000000001100110001111001111111100111100011001100000000000000000"); // 42 - add("0000000000011000000110000111111000011000000110000000000000000000"); // 43 - add("0000000000000000000000000000000000000000000110000001100000110000"); // 44 - add("0000000000000000000000000111111000000000000000000000000000000000"); // 45 - add("0000000000000000000000000000000000000000000110000001100000000000"); // 46 - add("0000000000000110000011000001100000110000011000000100000000000000"); // 47 - add("0000000000111100011001100110111001110110011001100011110000000000"); // 48 - add("0000000000011000001110000001100000011000000110000111111000000000"); // 49 - add("0000000000111100011001100000110000011000001100000111111000000000"); // 50 - add("0000000001111110000011000001100000001100011001100011110000000000"); // 51 - add("0000000000001100000111000011110001101100011111100000110000000000"); // 52 - add("0000000001111110011000000111110000000110011001100011110000000000"); // 53 - add("0000000000111100011000000111110001100110011001100011110000000000"); // 54 - add("0000000001111110000001100000110000011000001100000011000000000000"); // 55 - add("0000000000111100011001100011110001100110011001100011110000000000"); // 56 - add("0000000000111100011001100011111000000110000011000011100000000000"); // 57 - add("0000000000000000000110000001100000000000000110000001100000000000"); // 58 - add("0000000000000000000110000001100000000000000110000001100000110000"); // 59 - add("0000011000001100000110000011000000011000000011000000011000000000"); // 60 - add("0000000000000000011111100000000000000000011111100000000000000000"); // 61 - add("0110000000110000000110000000110000011000001100000110000000000000"); // 62 - add("0000000000111100011001100000110000011000000000000001100000000000"); // 63 - add("0000000000111100011001100110111001101110011000000011111000000000"); // 64 - add("0000000000011000001111000110011001100110011111100110011000000000"); // 65 - add("0000000001111100011001100111110001100110011001100111110000000000"); // 66 - add("0000000000111100011001100110000001100000011001100011110000000000"); // 67 - add("0000000001111000011011000110011001100110011011000111100000000000"); // 68 - add("0000000001111110011000000111110001100000011000000111111000000000"); // 69 - add("0000000001111110011000000111110001100000011000000110000000000000"); // 70 - add("0000000000111110011000000110000001101110011001100011111000000000"); // 71 - add("0000000001100110011001100111111001100110011001100110011000000000"); // 72 - add("0000000001111110000110000001100000011000000110000111111000000000"); // 73 - add("0000000000000110000001100000011000000110011001100011110000000000"); // 74 - add("0000000001100110011011000111100001111000011011000110011000000000"); // 75 - add("0000000001100000011000000110000001100000011000000111111000000000"); // 76 - add("0000000001100011011101110111111101101011011000110110001100000000"); // 77 - add("0000000001100110011101100111111001111110011011100110011000000000"); // 78 - add("0000000000111100011001100110011001100110011001100011110000000000"); // 79 - add("0000000001111100011001100110011001111100011000000110000000000000"); // 80 - add("0000000000111100011001100110011001100110011011000011011000000000"); // 81 - add("0000000001111100011001100110011001111100011011000110011000000000"); // 82 - add("0000000000111100011000000011110000000110000001100011110000000000"); // 83 - add("0000000001111110000110000001100000011000000110000001100000000000"); // 84 - add("0000000001100110011001100110011001100110011001100111111000000000"); // 85 - add("0000000001100110011001100110011001100110001111000001100000000000"); // 86 - add("0000000001100011011000110110101101111111011101110110001100000000"); // 87 - add("0000000001100110011001100011110000111100011001100110011000000000"); // 88 - add("0000000001100110011001100011110000011000000110000001100000000000"); // 89 - add("0000000001111110000011000001100000110000011000000111111000000000"); // 90 - add("0000000000011110000110000001100000011000000110000001111000000000"); // 91 - add("0000000001000000011000000011000000011000000011000000011000000000"); // 92 - add("0000000001111000000110000001100000011000000110000111100000000000"); // 93 - add("0000000000000010000100100011001001111110001100000001000000000000"); // 94 Enter symbol - add("0000000000000000000000000000000000000000000000001111111100000000"); // 95 - add("0000000001111100110000101001111010011110110000100111110000000000"); // 96 Copyright symbol - add("0000000000000000001111000000011000111110011001100011111000000000"); // 97 - add("0000000001100000011000000111110001100110011001100111110000000000"); // 98 - add("0000000000000000001111000110000001100000011000000011110000000000"); // 99 - add("0000000000000110000001100011111001100110011001100011111000000000"); // 100 - add("0000000000000000001111000110011001111110011000000011110000000000"); // 101 - add("0000000000001110000110000011111000011000000110000001100000000000"); // 102 - add("0000000000000000001111100110011001100110001111100000011001111100"); // 103 - add("0000000001100000011000000111110001100110011001100110011000000000"); // 104 - add("0000000000011000000000000011100000011000000110000011110000000000"); // 105 - add("0000000000000110000000000000011000000110000001100000011000111100"); // 106 - add("0000000001100000011000000110110001111000011011000110011000000000"); // 107 - add("0000000000111000000110000001100000011000000110000011110000000000"); // 108 - add("0000000000000000011001100111111101111111011010110110001100000000"); // 109 - add("0000000000000000011111000110011001100110011001100110011000000000"); // 110 - add("0000000000000000001111000110011001100110011001100011110000000000"); // 111 - add("0000000000000000011111000110011001100110011111000110000001100000"); // 112 - add("0000000000000000001111100110011001100110001111100000011000000110"); // 113 - add("0000000000000000011111000110011001100000011000000110000000000000"); // 114 - add("0000000000000000001111100110000000111100000001100111110000000000"); // 115 - add("0000000000011000011111100001100000011000000110000000111000000000"); // 116 - add("0000000000000000011001100110011001100110011001100011111000000000"); // 117 - add("0000000000000000011001100110011001100110001111000001100000000000"); // 118 - add("0000000000000000011000110110101101111111001111100011011000000000"); // 119 - add("0000000000000000011001100011110000011000001111000110011000000000"); // 120 - add("0000000000000000011001100110011001100110001111100000110001111000"); // 121 - add("0000000000000000011111100000110000011000001100000111111000000000"); // 122 - add("0000111000011000000110000011000000011000000110000000111000000000"); // 123 - add("0001100000011000000110000001100000011000000110000001100000000000"); // 124 - add("0111000000011000000110000000110000011000000110000111000000000000"); // 125 - add("1100000011000000110000001100000011000000110000001100000011000000"); // 126 Half cursor - add("1111111111111111111111111111111111111111111111111111111111111111"); // 127 Cursor - - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); - add("0000000000000000000000000000000000000000000000000000000000000000"); -} diff --git a/0.4A/PTM/t_charset.h b/0.4A/PTM/t_charset.h deleted file mode 100644 index 527217a..0000000 --- a/0.4A/PTM/t_charset.h +++ /dev/null @@ -1,28 +0,0 @@ -#pragma once -#include "t_list.h" -#include "t_binary.h" -#include "t_index.h" - -class t_charset -{ -public: - static const int char_w = 8; - static const int char_h = 8; - - t_charset(); - t_charset(const t_charset& other); - t_charset& operator=(const t_charset& other); - - void remove_all(); - void add(const t_binary& bits); - t_binary& get(t_index index); - void set(t_index index, const t_binary& bits); - void set_row(t_index chr_index, t_index row, const t_binary& bits); - int size() const; - void reset(); - -private: - t_list chars; - - void copy_from(const t_charset& other); -}; diff --git a/0.4A/PTM/t_color.cpp b/0.4A/PTM/t_color.cpp deleted file mode 100644 index 9e56704..0000000 --- a/0.4A/PTM/t_color.cpp +++ /dev/null @@ -1,83 +0,0 @@ -#include "t_color.h" -#include "t_util.h" - -t_color t_color::invalid = 0x000000; - -t_color::t_color() : r(0), g(0), b(0) -{ -} - -t_color::t_color(int r, int g, int b) : r(r), g(g), b(b) -{ -} - -t_color::t_color(RGB rgb) -{ - unpack_rgb(rgb, &r, &g, &b); -} - -t_color::t_color(const t_color& other) -{ - r = other.r; - g = other.g; - b = other.b; -} - -bool t_color::operator==(const t_color& other) const -{ - return r == other.r && g == other.g && b == other.b; -} - -t_color& t_color::operator=(const t_color& other) -{ - if (this == &other) - return *this; - - r = other.r; - g = other.g; - b = other.b; - - return *this; -} - -RGB t_color::to_rgb() const -{ - return pack_rgb(r, g, b); -} - -RGB t_color::pack_rgb(int r, int g, int b) -{ - return (r << 16) | (g << 8) | b; -} - -void t_color::unpack_rgb(RGB rgb, int* r, int* g, int* b) -{ - *r = (rgb >> 16) & 0xFF; - *g = (rgb >> 8) & 0xFF; - *b = rgb & 0xFF; -} - -t_color t_color::get_random() -{ - return t_color(t_util::rnd(0, 255), t_util::rnd(0, 255), t_util::rnd(0, 255)); -} - -void t_color::set(RGB rgb) -{ - unpack_rgb(rgb, &r, &g, &b); -} - -void t_color::set(int r, int g, int b) -{ - this->r = r; - this->g = g; - this->b = b; -} - -void t_color::set_r(int r) { this->r = r; } -void t_color::set_g(int g) { this->g = g; } -void t_color::set_b(int b) { this->b = b; } - -int t_color::get_r() const { return r; } -int t_color::get_g() const { return g; } -int t_color::get_b() const { return b; } diff --git a/0.4A/PTM/t_color.h b/0.4A/PTM/t_color.h deleted file mode 100644 index cd1b981..0000000 --- a/0.4A/PTM/t_color.h +++ /dev/null @@ -1,36 +0,0 @@ -#pragma once -#include "t_rgb.h" - -class t_color -{ -public: - static t_color invalid; - - t_color(); - t_color(RGB rgb); - t_color(int r, int g, int b); - t_color(const t_color& other); - - bool operator==(const t_color& other) const; - t_color& operator=(const t_color& other); - - RGB to_rgb() const; - static RGB pack_rgb(int r, int g, int b); - static void unpack_rgb(RGB rgb, int* r, int* g, int* b); - static t_color get_random(); - - void set(RGB rgb); - void set(int r, int g, int b); - void set_r(int r); - void set_g(int g); - void set_b(int b); - int get_r() const; - int get_g() const; - int get_b() const; - -private: - int r = 0; - int g = 0; - int b = 0; -}; - diff --git a/0.4A/PTM/t_data.cpp b/0.4A/PTM/t_data.cpp deleted file mode 100644 index ae295a5..0000000 --- a/0.4A/PTM/t_data.cpp +++ /dev/null @@ -1,62 +0,0 @@ -#include "t_data.h" - -t_data::t_data() -{ -} - -t_data::~t_data() -{ -} - -t_data::t_data(const t_data& other) -{ - data = other.data; -} - -void t_data::clear() -{ - data.clear(); -} - -void t_data::set(const t_string& key, const t_string& value) -{ - data[key] = value; -} - -void t_data::set(const t_string& key, int value) -{ - set(key, t_string::from_int(value)); -} - -const t_string& t_data::get_str(const t_string& key) -{ - return data[key]; -} - -const int t_data::get_int(const t_string& key) -{ - return data[key].to_int(); -} - -bool t_data::has(const t_string& key) -{ - return data.contains(key); -} - -bool t_data::has(const t_string& key, const t_string& value) -{ - if (!has(key)) - return false; - - return data[key] == value; -} - -const t_dict& t_data::get_all() const -{ - return data; -} - -bool t_data::empty() const -{ - return data.empty(); -} diff --git a/0.4A/PTM/t_data.h b/0.4A/PTM/t_data.h deleted file mode 100644 index ecc82c2..0000000 --- a/0.4A/PTM/t_data.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include "t_string.h" -#include "t_dict.h" - -class t_data -{ -public: - t_data(); - ~t_data(); - t_data(const t_data& other); - - void clear(); - void set(const t_string& key, const t_string& value); - void set(const t_string& key, int value); - const t_string& get_str(const t_string& key); - const int get_int(const t_string& key); - bool has(const t_string& key); - bool has(const t_string& key, const t_string& value); - const t_dict& get_all() const; - bool empty() const; - -private: - t_dict data; -}; diff --git a/0.4A/PTM/t_defaults.h b/0.4A/PTM/t_defaults.h deleted file mode 100644 index 18910cb..0000000 --- a/0.4A/PTM/t_defaults.h +++ /dev/null @@ -1,15 +0,0 @@ -#pragma once -#include "t_string.h" -#include "t_color.h" - -struct t_defaults -{ - const t_string wnd_title = "PTM"; - - const int wnd_buffer_w = 360; - const int wnd_buffer_h = 200; - const int wnd_stretch_w = 3; - const int wnd_stretch_h = 3; - - const t_color back_color = 0x000000; -}; diff --git a/0.4A/PTM/t_dict.cpp b/0.4A/PTM/t_dict.cpp deleted file mode 100644 index 420f15a..0000000 --- a/0.4A/PTM/t_dict.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "t_dict.h" diff --git a/0.4A/PTM/t_dict.h b/0.4A/PTM/t_dict.h deleted file mode 100644 index 04e69e0..0000000 --- a/0.4A/PTM/t_dict.h +++ /dev/null @@ -1,9 +0,0 @@ -#pragma once -#include -#include - -template -using t_dict = std::unordered_map; - -template -using t_ordered_dict = std::map; diff --git a/0.4A/PTM/t_image.cpp b/0.4A/PTM/t_image.cpp deleted file mode 100644 index 44a65a5..0000000 --- a/0.4A/PTM/t_image.cpp +++ /dev/null @@ -1,117 +0,0 @@ -#include -#include "t_image.h" - -t_image::t_image() -{ -} - -t_image::t_image(int w, int h, const t_color& back_color) -{ - width = w; - height = h; - - for (int i = 0; i < w * h; i++) - pixels.emplace_back(back_color); -} - -t_image::t_image(const t_image& other) -{ - width = other.width; - height = other.height; - - for (int i = 0; i < width * height; i++) - pixels.emplace_back(other.pixels[i]); -} - -t_image::~t_image() -{ - pixels.clear(); -} - -void t_image::set_pixel(int x, int y, const t_color& color) -{ - if (y >= 0 && x >= 0 && y < height && x < width) - pixels[y * width + x] = color; -} - -const t_color& t_image::get_pixel(int x, int y) const -{ - if (y >= 0 && x >= 0 && y < height && x < width) - return pixels[y * width + x]; - - return t_color::invalid; -} - -const t_list& t_image::get_pixels() const -{ - return pixels; -} - -void t_image::set_transparency_key(const t_color& color) -{ - transparency_key = color; - transparent = true; -} - -const t_color& t_image::get_transparency_key() const -{ - return transparency_key; -} - -void t_image::set_transparent(bool transp) -{ - transparent = transp; -} - -bool t_image::is_transparent() const -{ - return transparent; -} - -int t_image::get_width() const -{ - return width; -} - -int t_image::get_height() const -{ - return height; -} - -bool t_image::load(const t_string& filename) -{ - pixels.clear(); - - SDL_Surface* img = SDL_LoadBMP(filename.c_str()); - if (!img) - return false; - - width = img->w; - height = img->h; - - if (SDL_MUSTLOCK(img)) { - if (!SDL_LockSurface(img)) - return false; - } - - uint8_t* surface_pixels = static_cast(img->pixels); - const SDL_PixelFormatDetails* format = SDL_GetPixelFormatDetails(img->format); - - for (int y = 0; y < img->h; ++y) { - for (int x = 0; x < img->w; ++x) { - uint32_t* pixelAddr = reinterpret_cast( - surface_pixels + y * img->pitch + x * format->bytes_per_pixel); - - uint8_t r, g, b, a; - SDL_GetRGBA(*pixelAddr, format, nullptr, &r, &g, &b, &a); - pixels.emplace_back(r, g, b); - } - } - - if (SDL_MUSTLOCK(img)) - SDL_UnlockSurface(img); - - SDL_DestroySurface(img); - - return true; -} diff --git a/0.4A/PTM/t_image.h b/0.4A/PTM/t_image.h deleted file mode 100644 index e0497f2..0000000 --- a/0.4A/PTM/t_image.h +++ /dev/null @@ -1,31 +0,0 @@ -#pragma once -#include "t_color.h" -#include "t_list.h" -#include "t_string.h" - -class t_image -{ -public: - t_image(); - t_image(int w, int h, const t_color& back_color); - t_image(const t_image& other); - ~t_image(); - - void set_pixel(int x, int y, const t_color& color); - const t_color& get_pixel(int x, int y) const; - const t_list& get_pixels() const; - void set_transparency_key(const t_color& color); - const t_color& get_transparency_key() const; - void set_transparent(bool transp); - bool is_transparent() const; - int get_width() const; - int get_height() const; - bool load(const t_string& filename); - -private: - int width = 0; - int height = 0; - t_list pixels; - bool transparent = false; - t_color transparency_key; -}; diff --git a/0.4A/PTM/t_image_pool.cpp b/0.4A/PTM/t_image_pool.cpp deleted file mode 100644 index 04dbe7a..0000000 --- a/0.4A/PTM/t_image_pool.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "t_image_pool.h" - -t_image_pool::t_image_pool() -{ -} - -t_image_pool::~t_image_pool() -{ - images.clear(); -} - -t_index t_image_pool::new_image(int w, int h, const t_color& color) -{ - images.emplace_back(w, h, color); - - return images.size() - 1; -} - -void t_image_pool::new_images(int w, int h, const t_color& color, int count) -{ - for (int i = 0; i < count; i++) - new_image(w, h, color); -} - -t_image* t_image_pool::get(t_index index) -{ - if (index >= 0 && index < images.size()) - return &images[index]; - - return nullptr; -} - -const t_list& t_image_pool::get_all() -{ - return images; -} - -void t_image_pool::delete_all() -{ - images.clear(); -} - -int t_image_pool::size() const -{ - return images.size(); -} diff --git a/0.4A/PTM/t_image_pool.h b/0.4A/PTM/t_image_pool.h deleted file mode 100644 index 6c9b4b4..0000000 --- a/0.4A/PTM/t_image_pool.h +++ /dev/null @@ -1,21 +0,0 @@ -#pragma once -#include "t_image.h" -#include "t_list.h" -#include "t_index.h" - -class t_image_pool -{ -public: - t_image_pool(); - ~t_image_pool(); - - t_index new_image(int w, int h, const t_color& color); - void new_images(int w, int h, const t_color& color, int count); - t_image* get(t_index index); - const t_list& get_all(); - void delete_all(); - int size() const; - -private: - t_list images; -}; diff --git a/0.4A/PTM/t_index.h b/0.4A/PTM/t_index.h deleted file mode 100644 index eff558c..0000000 --- a/0.4A/PTM/t_index.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -using t_index = int; diff --git a/0.4A/PTM/t_keyboard.cpp b/0.4A/PTM/t_keyboard.cpp deleted file mode 100644 index 93336e2..0000000 --- a/0.4A/PTM/t_keyboard.cpp +++ /dev/null @@ -1,6 +0,0 @@ -#include "t_keyboard.h" - -bool t_keyboard::alt() -{ - return SDL_GetModState() & SDL_KMOD_ALT; -} diff --git a/0.4A/PTM/t_keyboard.h b/0.4A/PTM/t_keyboard.h deleted file mode 100644 index c782066..0000000 --- a/0.4A/PTM/t_keyboard.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once -#include - -using t_keycode = SDL_Keycode; -using t_keymod = SDL_Keymod; - -class t_keyboard -{ -public: - bool alt(); -}; diff --git a/0.4A/PTM/t_list.cpp b/0.4A/PTM/t_list.cpp deleted file mode 100644 index f3b2a57..0000000 --- a/0.4A/PTM/t_list.cpp +++ /dev/null @@ -1 +0,0 @@ -#include "t_list.h" diff --git a/0.4A/PTM/t_list.h b/0.4A/PTM/t_list.h deleted file mode 100644 index 71d578c..0000000 --- a/0.4A/PTM/t_list.h +++ /dev/null @@ -1,5 +0,0 @@ -#pragma once -#include - -template -using t_list = std::vector; diff --git a/0.4A/PTM/t_main_window.cpp b/0.4A/PTM/t_main_window.cpp deleted file mode 100644 index f9fdd47..0000000 --- a/0.4A/PTM/t_main_window.cpp +++ /dev/null @@ -1,114 +0,0 @@ -#include -#include "t_main_window.h" -#include "t_color.h" - -const RGB out_of_bounds_color = t_color::invalid.to_rgb(); - -t_main_window::t_main_window() -{ -} - -t_main_window::~t_main_window() -{ - close(); -} - -void t_main_window::open(const t_string& title, int buffer_w, int buffer_h, int stretch_w, int stretch_h) -{ - this->buffer_w = buffer_w; - this->buffer_h = buffer_h; - - buffer_len = buffer_w * buffer_h * sizeof(int); - buffer = new int[buffer_len]; - - SDL_CreateWindowAndRenderer(title.c_str(), buffer_w * stretch_w, buffer_h * stretch_h, SDL_WINDOW_HIDDEN, &wnd, &rend); - SDL_SetWindowPosition(wnd, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED); - - tex = SDL_CreateTexture(rend, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, buffer_w, buffer_h); - - SDL_SetTextureScaleMode(tex, SDL_SCALEMODE_NEAREST); - SDL_SetRenderLogicalPresentation(rend, buffer_w, buffer_h, SDL_LOGICAL_PRESENTATION_STRETCH); - SDL_SetRenderDrawBlendMode(rend, SDL_BLENDMODE_NONE); - SDL_SetTextureBlendMode(tex, SDL_BLENDMODE_NONE); - SDL_SetRenderTarget(rend, tex); - SDL_RenderClear(rend); - SDL_RenderPresent(rend); - - clear(0x000000); - update(); - - SDL_ShowWindow(wnd); - - created = true; -} - -bool t_main_window::is_open() const -{ - return created; -} - -void t_main_window::close() -{ - SDL_DestroyRenderer(rend); - rend = nullptr; - SDL_DestroyWindow(wnd); - wnd = nullptr; - delete buffer; - buffer = nullptr; - - created = false; -} - -void t_main_window::update() -{ - static void* pixels; - static int pitch; - SDL_LockTexture(tex, nullptr, &pixels, &pitch); - SDL_memcpy(pixels, buffer, buffer_len); - SDL_UnlockTexture(tex); - SDL_RenderTexture(rend, tex, nullptr, nullptr); - SDL_RenderPresent(rend); -} - -static std::random_device rd; -static std::mt19937 gen(rd()); -static std::uniform_int_distribution dis(0x000000, 0xffffff); - -void t_main_window::draw_test_frame() -{ - for (int i = 0; i < buffer_len; i++) - set_pixel(i, dis(gen)); -} - -void t_main_window::clear(const RGB& back_color) -{ - for (int i = 0; i < buffer_len; i++) - set_pixel(i, back_color); -} - -void t_main_window::set_pixel(int i, const RGB& color) -{ - buffer[i] = color; -} - -void t_main_window::set_pixel(int x, int y, const RGB& color) -{ - if (y >= 0 && x >= 0 && y < buffer_h && x < buffer_w) - buffer[y * buffer_w + x] = color; -} - -const RGB& t_main_window::get_pixel(int x, int y) const -{ - if (y >= 0 && x >= 0 && y < buffer_h && x < buffer_w) - return buffer[y * buffer_w + x]; - - return out_of_bounds_color; -} - -void t_main_window::toggle_fullscreen() -{ - Uint32 flag = SDL_WINDOW_FULLSCREEN; - Uint32 is_full = SDL_GetWindowFlags(wnd) & flag; - SDL_SetWindowFullscreen(wnd, is_full ? 0 : flag); - update(); -} diff --git a/0.4A/PTM/t_main_window.h b/0.4A/PTM/t_main_window.h deleted file mode 100644 index b123d93..0000000 --- a/0.4A/PTM/t_main_window.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#include -#include "t_string.h" -#include "t_rgb.h" - -class t_main_window -{ -public: - t_main_window(); - ~t_main_window(); - - void open(const t_string& title, int buffer_w, int buffer_h, int stretch_w, int stretch_h); - bool is_open() const; - void close(); - void update(); - void draw_test_frame(); - void clear(const RGB& back_color); - void set_pixel(int i, const RGB& color); - void set_pixel(int x, int y, const RGB& color); - const RGB& get_pixel(int x, int y) const; - void toggle_fullscreen(); - -private: - bool created = false; - SDL_Window* wnd = nullptr; - SDL_Renderer* rend = nullptr; - SDL_Texture* tex = nullptr; - int* buffer = nullptr; - int buffer_len = 0; - int buffer_h = 0; - int buffer_w = 0; -}; diff --git a/0.4A/PTM/t_mouse.cpp b/0.4A/PTM/t_mouse.cpp deleted file mode 100644 index bf32a75..0000000 --- a/0.4A/PTM/t_mouse.cpp +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include "t_mouse.h" - -int t_mouse::get_x() -{ - float x = 0.0; - SDL_GetMouseState(&x, nullptr); - return x; -} - -int t_mouse::get_y() -{ - float y = 0.0; - SDL_GetMouseState(nullptr, &y); - return y; -} - -bool t_mouse::btn_left() -{ - return SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON_MASK(1); -} - -bool t_mouse::btn_middle() -{ - return SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON_MASK(2); -} - -bool t_mouse::btn_right() -{ - return SDL_GetMouseState(nullptr, nullptr) & SDL_BUTTON_MASK(3); -} diff --git a/0.4A/PTM/t_mouse.h b/0.4A/PTM/t_mouse.h deleted file mode 100644 index 3f638b9..0000000 --- a/0.4A/PTM/t_mouse.h +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -class t_mouse -{ -public: - int get_x(); - int get_y(); - - bool btn_left(); - bool btn_middle(); - bool btn_right(); -}; diff --git a/0.4A/PTM/t_palette.cpp b/0.4A/PTM/t_palette.cpp deleted file mode 100644 index 6dd788a..0000000 --- a/0.4A/PTM/t_palette.cpp +++ /dev/null @@ -1,575 +0,0 @@ -#include "t_palette.h" - -t_palette::t_palette() -{ - reset(); -} - -t_palette::t_palette(const t_palette& other) -{ - copy_from(other); -} - -t_palette& t_palette::operator=(const t_palette& other) -{ - if (this == &other) - return *this; - - copy_from(other); - - return *this; -} - -void t_palette::copy_from(const t_palette& other) -{ - remove_all(); - for (int i = 0; i < other.colors.size(); i++) { - colors.emplace_back(other.colors[i]); - } -} - -void t_palette::remove_all() -{ - colors.clear(); -} - -void t_palette::add(const t_color& color) -{ - colors.emplace_back(color); -} - -t_color& t_palette::get(t_index index) -{ - return colors[index]; -} - -void t_palette::set(t_index index, const t_color& color) -{ - colors[index] = color; -} - -int t_palette::size() const -{ - return (int)colors.size(); -} - -void t_palette::reset() -{ - remove_all(); - - add(0x000000); - add(0x111111); - add(0x222222); - add(0x333333); - add(0x444444); - add(0x555555); - add(0x666666); - add(0x777777); - add(0x888888); - add(0x999999); - add(0xaaaaaa); - add(0xbbbbbb); - add(0xcccccc); - add(0xdddddd); - add(0xeeeeee); - add(0xffffff); - add(0x007f7f); - add(0x3fbfbf); - add(0x00ffff); - add(0xbfffff); - add(0x8181ff); - add(0x0000ff); - add(0x3f3fbf); - add(0x00007f); - add(0x0f0f50); - add(0x7f007f); - add(0xbf3fbf); - add(0xf500f5); - add(0xfd81ff); - add(0xffc0cb); - add(0xff8181); - add(0xff0000); - add(0xbf3f3f); - add(0x7f0000); - add(0x551414); - add(0x7f3f00); - add(0xbf7f3f); - add(0xff7f00); - add(0xffbf81); - add(0xffffbf); - add(0xffff00); - add(0xbfbf3f); - add(0x7f7f00); - add(0x007f00); - add(0x3fbf3f); - add(0x00ff00); - add(0xafffaf); - add(0x00bfff); - add(0x007fff); - add(0x4b7dc8); - add(0xbcafc0); - add(0xcbaa89); - add(0xa6a090); - add(0x7e9494); - add(0x6e8287); - add(0x7e6e60); - add(0xa0695f); - add(0xc07872); - add(0xd08a74); - add(0xe19b7d); - add(0xebaa8c); - add(0xf5b99b); - add(0xf6c8af); - add(0xf5e1d2); - add(0x7f00ff); - add(0x573b3b); - add(0x73413c); - add(0x8e5555); - add(0xab7373); - add(0xc78f8f); - add(0xe3abab); - add(0xf8d2da); - add(0xe3c7ab); - add(0xc49e73); - add(0x8f7357); - add(0x73573b); - add(0x3b2d1f); - add(0x414123); - add(0x73733b); - add(0x8f8f57); - add(0xa2a255); - add(0xb5b572); - add(0xc7c78f); - add(0xdadaab); - add(0xededc7); - add(0xc7e3ab); - add(0xabc78f); - add(0x8ebe55); - add(0x738f57); - add(0x587d3e); - add(0x465032); - add(0x191e0f); - add(0x235037); - add(0x3b573b); - add(0x506450); - add(0x3b7349); - add(0x578f57); - add(0x73ab73); - add(0x64c082); - add(0x8fc78f); - add(0xa2d8a2); - add(0xe1f8fa); - add(0xb4eeca); - add(0xabe3c5); - add(0x87b48e); - add(0x507d5f); - add(0x0f6946); - add(0x1e2d23); - add(0x234146); - add(0x3b7373); - add(0x64abab); - add(0x8fc7c7); - add(0xabe3e3); - add(0xc7f1f1); - add(0xbed2f0); - add(0xabc7e3); - add(0xa8b9dc); - add(0x8fabc7); - add(0x578fc7); - add(0x57738f); - add(0x3b5773); - add(0x0f192d); - add(0x1f1f3b); - add(0x3b3b57); - add(0x494973); - add(0x57578f); - add(0x736eaa); - add(0x7676ca); - add(0x8f8fc7); - add(0xababe3); - add(0xd0daf8); - add(0xe3e3ff); - add(0xab8fc7); - add(0x8f57c7); - add(0x73578f); - add(0x573b73); - add(0x3c233c); - add(0x463246); - add(0x724072); - add(0x8f578f); - add(0xab57ab); - add(0xab73ab); - add(0xebace1); - add(0xffdcf5); - add(0xe3c7e3); - add(0xe1b9d2); - add(0xd7a0be); - add(0xc78fb9); - add(0xc87da0); - add(0xc35a91); - add(0x4b2837); - add(0x321623); - add(0x280a1e); - add(0x401811); - add(0x621800); - add(0xa5140a); - add(0xda2010); - add(0xd5524a); - add(0xff3c0a); - add(0xf55a32); - add(0xff6262); - add(0xf6bd31); - add(0xffa53c); - add(0xd79b0f); - add(0xda6e0a); - add(0xb45a00); - add(0xa04b05); - add(0x5f3214); - add(0x53500a); - add(0x626200); - add(0x8c805a); - add(0xac9400); - add(0xb1b10a); - add(0xe6d55a); - add(0xffd510); - add(0xffea4a); - add(0xc8ff41); - add(0x9bf046); - add(0x96dc19); - add(0x73c805); - add(0x6aa805); - add(0x3c6e14); - add(0x283405); - add(0x204608); - add(0x0c5c0c); - add(0x149605); - add(0x0ad70a); - add(0x14e60a); - add(0x7dff73); - add(0x4bf05a); - add(0x00c514); - add(0x05b450); - add(0x1c8c4e); - add(0x123832); - add(0x129880); - add(0x06c491); - add(0x00de6a); - add(0x2deba8); - add(0x3cfea5); - add(0x6affcd); - add(0x91ebff); - add(0x55e6ff); - add(0x7dd7f0); - add(0x08ded5); - add(0x109cde); - add(0x055a5c); - add(0x162c52); - add(0x0f377d); - add(0x004a9c); - add(0x326496); - add(0x0052f6); - add(0x186abd); - add(0x2378dc); - add(0x699dc3); - add(0x4aa4ff); - add(0x90b0ff); - add(0x5ac5ff); - add(0xbeb9fa); - add(0x786ef0); - add(0x4a5aff); - add(0x6241f6); - add(0x3c3cf5); - add(0x101cda); - add(0x0010bd); - add(0x231094); - add(0x0c2148); - add(0x5010b0); - add(0x6010d0); - add(0x8732d2); - add(0x9c41ff); - add(0xbd62ff); - add(0xb991ff); - add(0xd7a5ff); - add(0xd7c3fa); - add(0xf8c6fc); - add(0xe673ff); - add(0xff52ff); - add(0xda20e0); - add(0xbd29ff); - add(0xbd10c5); - add(0x8c14be); - add(0x5a187b); - add(0x641464); - add(0x410062); - add(0x320a46); - add(0x551937); - add(0xa01982); - add(0xc80078); - add(0xff50bf); - add(0xff6ac5); - add(0xfaa0b9); - add(0xfc3a8c); - add(0xe61e78); - add(0xbd1039); - add(0x98344d); - add(0x911437); - - /* Inspired by Atari 5200 - add(0x000000); - add(0x111111); - add(0x222222); - add(0x333333); - add(0x444444); - add(0x555555); - add(0x666666); - add(0x777777); - add(0x888888); - add(0x999999); - add(0xaaaaaa); - add(0xbbbbbb); - add(0xcccccc); - add(0xdddddd); - add(0xeeeeee); - add(0xffffff); - add(0x190700); - add(0x2a1800); - add(0x3b2900); - add(0x4c3a00); - add(0x5d4b00); - add(0x6e5c00); - add(0x7f6d00); - add(0x907e09); - add(0xa18f1a); - add(0xb3a02b); - add(0xc3b13c); - add(0xd4c24d); - add(0xe5d35e); - add(0xf7e46f); - add(0xfff582); - add(0xffff96); - add(0x310000); - add(0x3f0000); - add(0x531700); - add(0x642800); - add(0x753900); - add(0x864a00); - add(0x975b0a); - add(0xa86c1b); - add(0xb97d2c); - add(0xca8e3d); - add(0xdb9f4e); - add(0xecb05f); - add(0xfdc170); - add(0xffd285); - add(0xffe39c); - add(0xfff4b2); - add(0x420404); - add(0x4f0000); - add(0x600800); - add(0x711900); - add(0x822a0d); - add(0x933b1e); - add(0xa44c2f); - add(0xb55d40); - add(0xc66e51); - add(0xd77f62); - add(0xe89073); - add(0xf9a183); - add(0xffb298); - add(0xffc3ae); - add(0xffd4c4); - add(0xffe5da); - add(0x410103); - add(0x50000f); - add(0x61001b); - add(0x720f2b); - add(0x83203c); - add(0x94314d); - add(0xa5425e); - add(0xb6536f); - add(0xc76480); - add(0xd87591); - add(0xe986a2); - add(0xfa97b3); - add(0xffa8c8); - add(0xffb9de); - add(0xffcaef); - add(0xfbdcf6); - add(0x330035); - add(0x440041); - add(0x55004c); - add(0x660c5c); - add(0x771d6d); - add(0x882e7e); - add(0x993f8f); - add(0xaa50a0); - add(0xbb61b1); - add(0xcc72c2); - add(0xdd83d3); - add(0xee94e4); - add(0xffa5e4); - add(0xffb6e9); - add(0xffc7ee); - add(0xffd8f3); - add(0x1d005c); - add(0x2e0068); - add(0x400074); - add(0x511084); - add(0x622195); - add(0x7332a6); - add(0x8443b7); - add(0x9554c8); - add(0xa665d9); - add(0xb776ea); - add(0xc887eb); - add(0xd998eb); - add(0xe9a9ec); - add(0xfbbaeb); - add(0xffcbef); - add(0xffdff9); - add(0x020071); - add(0x13007d); - add(0x240b8c); - add(0x351c9d); - add(0x462dae); - add(0x573ebf); - add(0x684fd0); - add(0x7960e1); - add(0x8a71f2); - add(0x9b82f7); - add(0xac93f7); - add(0xbda4f7); - add(0xceb5f7); - add(0xdfc6f7); - add(0xf0d7f7); - add(0xffe8f8); - add(0x000068); - add(0x000a7c); - add(0x081b90); - add(0x192ca1); - add(0x2a3db2); - add(0x3b4ec3); - add(0x4c5fd4); - add(0x5d70e5); - add(0x6e81f6); - add(0x7f92ff); - add(0x90a3ff); - add(0xa1b4ff); - add(0xb2c5ff); - add(0xc3d6ff); - add(0xd4e7ff); - add(0xe5f8ff); - add(0x000a4d); - add(0x001b63); - add(0x002c79); - add(0x023d8f); - add(0x134ea0); - add(0x245fb1); - add(0x3570c2); - add(0x4681d3); - add(0x5792e4); - add(0x68a3f5); - add(0x79b4ff); - add(0x8ac5ff); - add(0x9bd6ff); - add(0xace7ff); - add(0xbdf8ff); - add(0xceffff); - add(0x001a26); - add(0x002b3c); - add(0x003c52); - add(0x004d68); - add(0x065e7c); - add(0x176f8d); - add(0x28809e); - add(0x3991af); - add(0x4aa2c0); - add(0x5bb3d1); - add(0x6cc4e2); - add(0x7dd5f3); - add(0x8ee6ff); - add(0x9ff7ff); - add(0xb0ffff); - add(0xc1ffff); - add(0x01250a); - add(0x023610); - add(0x004622); - add(0x005738); - add(0x05684d); - add(0x16795e); - add(0x278a6f); - add(0x389b80); - add(0x49ac91); - add(0x5abda2); - add(0x6bceb3); - add(0x7cdfc4); - add(0x8df0d5); - add(0x9effe5); - add(0xaffff1); - add(0xc0fffd); - add(0x04260d); - add(0x043811); - add(0x054713); - add(0x005a1b); - add(0x106b1b); - add(0x217c2c); - add(0x328d3d); - add(0x439e4e); - add(0x54af5f); - add(0x65c070); - add(0x76d181); - add(0x87e292); - add(0x98f3a3); - add(0xa9ffb3); - add(0xbaffbf); - add(0xcbffcb); - add(0x00230a); - add(0x003510); - add(0x044613); - add(0x155613); - add(0x266713); - add(0x377813); - add(0x488914); - add(0x599a25); - add(0x6aab36); - add(0x7bbc47); - add(0x8ccd58); - add(0x9dde69); - add(0xaeef7a); - add(0xbfff8b); - add(0xd0ff97); - add(0xe1ffa3); - add(0x001707); - add(0x0e2808); - add(0x1f3908); - add(0x304a08); - add(0x415b08); - add(0x526c08); - add(0x637d08); - add(0x748e0d); - add(0x859f1e); - add(0x96b02f); - add(0xa7c140); - add(0xb8d251); - add(0xc9e362); - add(0xdaf473); - add(0xebff82); - add(0xfcff8e); - add(0x1b0701); - add(0x2c1801); - add(0x3c2900); - add(0x4d3b00); - add(0x5f4c00); - add(0x705e00); - add(0x816f00); - add(0x938009); - add(0xa4921a); - add(0xb2a02b); - add(0xc7b43d); - add(0xd8c64e); - add(0xead760); - add(0xf6e46f); - add(0xfffa84); - add(0xffff99); - */ -} diff --git a/0.4A/PTM/t_palette.h b/0.4A/PTM/t_palette.h deleted file mode 100644 index 696521c..0000000 --- a/0.4A/PTM/t_palette.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once -#include "t_list.h" -#include "t_color.h" -#include "t_index.h" - -class t_palette -{ -public: - t_palette(); - t_palette(const t_palette& other); - t_palette& operator=(const t_palette& other); - - void remove_all(); - void add(const t_color& color); - t_color& get(t_index index); - void set(t_index index, const t_color& color); - int size() const; - void reset(); - -private: - t_list colors; - - void copy_from(const t_palette& other); -}; diff --git a/0.4A/PTM/t_ptm.cpp b/0.4A/PTM/t_ptm.cpp deleted file mode 100644 index 309ded9..0000000 --- a/0.4A/PTM/t_ptm.cpp +++ /dev/null @@ -1,3 +0,0 @@ -#include "t_ptm.h" - -t_ptm ptm; diff --git a/0.4A/PTM/t_ptm.h b/0.4A/PTM/t_ptm.h deleted file mode 100644 index 01d197e..0000000 --- a/0.4A/PTM/t_ptm.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once -#include "t_system.h" -#include "t_defaults.h" -#include "t_keyboard.h" -#include "t_mouse.h" -#include "t_main_window.h" -#include "t_screen.h" -#include "t_charset.h" -#include "t_palette.h" -#include "t_image_pool.h" - -struct t_ptm -{ - const t_index invalid_index = -1; - - t_defaults defaults; - t_system sys; - t_keyboard kb; - t_mouse mouse; - t_main_window wnd; - t_screen scr; - t_charset font; - t_palette palette; - t_image_pool images; -}; - -extern t_ptm ptm; diff --git a/0.4A/PTM/t_rgb.h b/0.4A/PTM/t_rgb.h deleted file mode 100644 index d0a63e9..0000000 --- a/0.4A/PTM/t_rgb.h +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -using RGB = int; diff --git a/0.4A/PTM/t_screen.cpp b/0.4A/PTM/t_screen.cpp deleted file mode 100644 index 2fe5b4a..0000000 --- a/0.4A/PTM/t_screen.cpp +++ /dev/null @@ -1,105 +0,0 @@ -#include "t_screen.h" -#include "t_ptm.h" -#include "t_main_window.h" -#include "t_charset.h" -#include "t_image.h" -#include "t_image_pool.h" - -t_screen::t_screen() -{ -} - -t_screen::~t_screen() -{ -} - -void t_screen::update() -{ - ptm.wnd.update(); -} - -void t_screen::clear() -{ - ptm.wnd.clear(back_color.to_rgb()); -} - -void t_screen::set_backcolor(const t_color& color) -{ - back_color = color; -} - -const t_color& t_screen::get_backcolor() const -{ - return back_color; -} - -void t_screen::toggle_fullscreen() -{ - ptm.wnd.toggle_fullscreen(); -} - -void t_screen::draw_image(t_index img_index, int x, int y) -{ - const t_image* img = ptm.images.get(img_index); - if (!img) return; - - const int px = x; - for (int iy = 0; iy < img->get_height(); iy++) { - for (int ix = 0; ix < img->get_width(); ix++) { - const t_color& color = img->get_pixel(ix, iy); - if (!img->is_transparent() || img->get_transparency_key() != color) - ptm.wnd.set_pixel(x, y, color.to_rgb()); - - x++; - } - y++; - x = px; - } -} - -void t_screen::putch(t_index ch, int x, int y, const t_color& fore_color) -{ - putch(ch, x, y, fore_color, 0, true); -} - -void t_screen::putch(t_index ch, int x, int y, const t_color& fore_color, const t_color& back_color) -{ - putch(ch, x, y, fore_color, back_color, false); -} - -void t_screen::print(const t_string& str, int x, int y, const t_color& fore_color) -{ - for (auto& ch : str.s_str()) - putch(ch, x++, y, fore_color); -} - -void t_screen::print(const t_string& str, int x, int y, const t_color& fore_color, const t_color& back_color) -{ - for (auto& ch : str.s_str()) - putch(ch, x++, y, fore_color, back_color); -} - -void t_screen::putch(t_index ch, int x, int y, const t_color& fore_color, const t_color& back_color, bool hide_back_color) -{ - const t_binary& bits = ptm.font.get(ch); - - x *= t_charset::char_w; - y *= t_charset::char_h; - - const int px = x; - for (auto& bit : bits.s_str()) { - if (hide_back_color) { - if (bit == '1') { - ptm.wnd.set_pixel(x, y, fore_color.to_rgb()); - } - } - else { - ptm.wnd.set_pixel(x, y, (bit == '1' ? fore_color : back_color).to_rgb()); - } - x++; - if (x >= px + t_charset::char_w) { - x = px; - y++; - } - } -} diff --git a/0.4A/PTM/t_screen.h b/0.4A/PTM/t_screen.h deleted file mode 100644 index aac935a..0000000 --- a/0.4A/PTM/t_screen.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once -#include "t_string.h" -#include "t_index.h" -#include "t_color.h" - -class t_screen -{ -public: - t_screen(); - ~t_screen(); - - void update(); - void clear(); - void set_backcolor(const t_color& color); - const t_color& get_backcolor() const; - void toggle_fullscreen(); - void draw_image(t_index img_index, int x, int y); - void putch(t_index ch, int x, int y, const t_color& fore_color); - void putch(t_index ch, int x, int y, const t_color& fore_color, const t_color& back_color); - void print(const t_string& str, int x, int y, const t_color& fore_color); - void print(const t_string& str, int x, int y, const t_color& fore_color, const t_color& back_color); - -private: - t_color back_color = t_color(0, 0, 0); - - void putch(t_index ch, int x, int y, const t_color& fore_color, const t_color& back_color, bool hide_back_color); -}; diff --git a/0.4A/PTM/t_string.cpp b/0.4A/PTM/t_string.cpp deleted file mode 100644 index a99c634..0000000 --- a/0.4A/PTM/t_string.cpp +++ /dev/null @@ -1,540 +0,0 @@ -#include -#include -#include -#include "t_string.h" - -t_string::t_string() : value("") -{ -} - -t_string::t_string(const char* str) : value(str) -{ -} - -t_string::t_string(const t_string& other) : value(other.value) -{ -} - -t_string::t_string(const std::string& other) : value(other) -{ -} - -t_string::t_string(const char& single_char) : value(1, single_char) -{ -} - -t_string::t_string(t_string&& other) noexcept : value(std::move(other.value)) -{ -} - -t_string::t_string(int value) : value(from_int(value)) -{ -} - -t_string::operator const std::string&() const -{ - return (const std::string&) value; -} - -bool t_string::operator==(const t_string& other) const -{ - return value == other.value; -} - -t_string& t_string::operator=(const char* other) -{ - value = other; - return *this; -} - -t_string& t_string::operator=(const t_string& other) -{ - if (this != &other) - value = other.value; - - return *this; -} - -t_string& t_string::operator=(const std::string& other) -{ - value = other; - return *this; -} - -t_string& t_string::operator=(t_string&& other) noexcept -{ - if (this != &other) - value = std::move(other.value); - - return *this; -} - -char& t_string::operator[](size_t index) -{ - return value[index]; -} - -const char& t_string::operator[](size_t index) const -{ - return value[index]; -} - -t_string& t_string::operator+=(const t_string& other) -{ - value += other.value; - return *this; -} - -t_string& t_string::operator+=(const int& ch) -{ - value.push_back(ch); - return *this; -} - -t_string t_string::operator+(const t_string& other) const -{ - return t_string(value + other.value); -} - -const std::string& t_string::s_str() const -{ - return value; -} - -const char* t_string::c_str() const noexcept -{ - return value.c_str(); -} - -size_t t_string::length() const noexcept -{ - return value.length(); -} - -bool t_string::has_length(int len) const noexcept -{ - return value.length() == len; -} - -bool t_string::has_length(int min, int max) const noexcept -{ - return value.length() >= min && value.length() <= max; -} - -int t_string::to_int() const -{ - t_string str = t_string(value).trim(); - if (str.empty()) - return 0; - - bool negative = str[0] == '-'; - bool positive = str[0] == '+'; - - if (negative || positive) - str = str.skip(1); - - int int_value = 0; - - try { - if ((str[0] == '0' && str[1] == 'x') || (str[0] == '&' && toupper(str[1]) == 'H')) - int_value = std::stoi(str.skip(2), nullptr, 16); - else if ((str[0] == '0' && str[1] == 'b') || (str[0] == '&' && toupper(str[1]) == 'B')) - int_value = std::stoi(str.skip(2), nullptr, 2); - else if (isdigit(str[0])) - int_value = std::stoi(str); - } - catch (std::out_of_range) { - int_value = 0; - } - - return negative ? -int_value : int_value; -} - -float t_string::to_float() const -{ - float float_value = 0.0f; - - t_string str = t_string(value).trim(); - - bool sign = str[0] == '-'; - if (sign) - str = str.skip(1); - - float_value = (float)std::atof(str.c_str()); - - return sign ? -float_value : float_value; -} - -void t_string::clear() noexcept -{ - value.clear(); -} - -bool t_string::empty() const noexcept -{ - return value.empty(); -} - -bool t_string::is_number() const noexcept -{ - std::string text = value; - if (text.starts_with("-")) - text = skip(1); - - std::string::const_iterator it = text.begin(); - while (it != text.end() && std::isdigit(*it)) ++it; - return !text.empty() && it == text.end(); -} - -t_string t_string::to_upper() const -{ - std::string result = value; - - for (unsigned i = 0; i < result.size(); i++) - result[i] = toupper(result[i]); - - return result; -} - -t_string t_string::to_lower() const -{ - std::string result = value; - - for (unsigned i = 0; i < result.size(); i++) - result[i] = tolower(result[i]); - - return result; -} - -t_string t_string::trim() const -{ - size_t first = value.find_first_not_of(" \t\n\r"); - if (first == std::string::npos) - return ""; - - size_t last = value.find_last_not_of(" \t\n\r"); - return value.substr(first, last - first + 1); -} - -t_string t_string::skip(int count) const -{ - return remove_first(count); -} - -t_string t_string::remove_first(int count) const -{ - if (count > value.length()) - return ""; - - return value.substr(count); -} - -t_string t_string::remove_last(int count) const -{ - if (count > value.length()) - return ""; - - return value.substr(0, value.length() - count); -} - -t_string t_string::remove_first_and_last(int count) const -{ - return remove_first(count).remove_last(count); -} - -t_string t_string::get_first(int count) const -{ - return value.substr(0, count); -} - -t_string t_string::get_last(int count) const -{ - if (value.size() < (unsigned)count) - return value; - - return value.substr(value.size() - count, count); -} - -t_list t_string::split(char delim, bool trim_tokens) const -{ - t_list elems; - std::string item; - std::stringstream ss(value); - - while (std::getline(ss, item, delim)) { - if (trim_tokens) - elems.emplace_back(t_string(item).trim()); - else - elems.emplace_back(item); - } - - return elems; -} - -t_list t_string::split_chunks(int chunk_size) const -{ - t_list tokens; - std::string token = ""; - - for (int i = 0; i < value.length(); i++) { - token += value[i]; - if (token.length() == chunk_size) { - tokens.push_back(token); - token = ""; - } - } - - if (!token.empty()) - tokens.push_back(token); - - return tokens; -} - -t_string t_string::substr(int first) const -{ - return value.substr(first); -} - -t_string t_string::substr(int first, int last) const -{ - last++; - - if (first < 0) - first = 0; - if (last > value.length() || last < first) - return ""; - - return value.substr(first, last - first); -} - -t_string t_string::replace(const t_string& original, const t_string& replacement) const -{ - if (original.empty()) - return ""; - - std::string replaced = value; - size_t startPos = 0; - - while ((startPos = replaced.find(original, startPos)) != std::string::npos) { - replaced.replace(startPos, original.length(), replacement); - startPos += replacement.length(); - } - - return replaced; -} - -t_string t_string::replace(const char& original, const char& replacement) const -{ - t_string replaced; - - for (auto& current : value) { - if (current == original) - replaced += replacement; - else - replaced += current; - } - - return replaced; -} - -t_string t_string::remove_all(const t_string& chars) const -{ - std::string result = value; - - for (unsigned int i = 0; i < chars.length(); i++) - result.erase(remove(result.begin(), result.end(), chars[i]), result.end()); - - return result; -} - -t_string t_string::reverse() const -{ - std::string reversed = value; - std::reverse(reversed.begin(), reversed.end()); - return reversed; -} - -bool t_string::starts_with(const t_string& prefix) const -{ - return value.starts_with(prefix.s_str()); -} - -bool t_string::ends_with(const t_string& suffix) const -{ - return value.ends_with(suffix.s_str()); -} - -bool t_string::starts_and_ends_with(const t_string& prefix, const t_string& suffix) const -{ - return starts_with(prefix) && ends_with(suffix); -} - -bool t_string::starts_and_ends_with(const t_string& same_preffix_and_suffix) const -{ - return starts_with(same_preffix_and_suffix) && ends_with(same_preffix_and_suffix); -} - -bool t_string::contains(const t_string& other) const -{ - return value.find(other) != std::string::npos; -} - -bool t_string::contains_only(const t_string& chars) const -{ - return std::all_of(value.begin(), value.end(), [&chars](char c) { - return chars.s_str().find(c) != std::string::npos; - }); -} - -bool t_string::contains_any(const t_string& chars) const -{ - return value.find_first_of(chars.s_str()) != std::string::npos; -} - -bool t_string::in(const t_list& strings) const -{ - return std::find(strings.begin(), strings.end(), value) != strings.end(); -} - -int t_string::index_of(const t_string& str) const -{ - return (int)value.find(str); -} - -int t_string::last_index_of(const t_string& str) const -{ - return (int)value.find_last_not_of(str); -} - -t_list t_string::find_all(const char& ch, size_t offset) -{ - t_list indexes; - - for (size_t i = offset; i < value.length(); i++) { - if (value[i] == ch) { - indexes.push_back((int)i); - } - } - - return indexes; -} - -int t_string::count(const char& ch) -{ - return (int)find_all(ch).size(); -} - -t_string t_string::fmt(const char* str, ...) -{ - char output[fmt_buf_maxlen] = { 0 }; - - va_list arg; - va_start(arg, str); - vsprintf_s(output, str, arg); - va_end(arg); - - return output; -} - -t_string t_string::from_int(int value) -{ - return std::to_string(value); -} - -t_string t_string::from_int(int value, int digits) -{ - const std::string result = from_int(value); - std::string padding = ""; - - for (int i = 0; i < digits - result.length(); i++) - padding += '0'; - - return padding + result; -} - -t_string t_string::from_float(float value) -{ - return std::to_string(value); -} - -t_string t_string::from_bool(bool value) -{ - return value ? "true" : "false"; -} - -t_string t_string::to_hex(int value) -{ - return fmt("%x", value); -} - -t_string t_string::to_hex(int value, int digits) -{ - const std::string hex = to_hex(value); - std::string padding = ""; - - for (int i = 0; i < digits - hex.length(); i++) - padding += '0'; - - return padding + hex; -} - -t_string t_string::to_binary(int value) -{ - std::string str = ""; - - while (value != 0) { - str = (value % 2 == 0 ? "0" : "1") + str; - value /= 2; - } - - return str; -} - -t_string t_string::to_binary(int value, int digits) -{ - const std::string binary = to_binary(value); - std::string padding = ""; - - for (int i = 0; i < digits - binary.length(); i++) - padding += '0'; - - return padding + binary; -} - -t_string t_string::join(const t_list& str_list, const t_string& separator) -{ - std::string str = ""; - - for (int i = 0; i < str_list.size(); i++) { - if (!separator.empty()) { - str += str_list[i]; - if (i < str_list.size() - 1) { - str += separator; - } - } - else { - str += str_list[i]; - } - } - - return str; -} - -t_string t_string::repeat(const t_string& str, int count) -{ - std::string result = ""; - for (int i = 0; i < count; i++) - result += str; - - return result; -} - -char t_string::to_upper(char ch) -{ - return toupper(ch); -} - -char t_string::to_lower(char ch) -{ - return tolower(ch); -} diff --git a/0.4A/PTM/t_string.h b/0.4A/PTM/t_string.h deleted file mode 100644 index 1da0bbb..0000000 --- a/0.4A/PTM/t_string.h +++ /dev/null @@ -1,96 +0,0 @@ -#pragma once -#include -#include "t_list.h" - -class t_string -{ -public: - t_string(); - t_string(const char* str); - t_string(const t_string& other); - t_string(const std::string& other); - t_string(const char& single_char); - t_string(t_string&& other) noexcept; - t_string(int value); - ~t_string() = default; - - operator const std::string&() const; - bool operator==(const t_string& other) const; - t_string& operator=(const char* other); - t_string& operator=(const t_string& other); - t_string& operator=(const std::string& other); - t_string& operator=(t_string&& other) noexcept; - char& operator[](size_t index); - const char& operator[](size_t index) const; - t_string& operator+=(const t_string& other); - t_string& operator+=(const int& ch); - t_string operator+(const t_string& other) const; - - static t_string fmt(const char* str, ...); - static t_string from_int(int value); - static t_string from_int(int value, int digits); - static t_string from_float(float value); - static t_string from_bool(bool value); - static t_string to_hex(int value); - static t_string to_hex(int value, int digits); - static t_string to_binary(int value); - static t_string to_binary(int value, int digits); - static t_string join(const t_list& str_list, const t_string& separator); - static t_string repeat(const t_string& str, int count); - static char to_upper(char ch); - static char to_lower(char ch); - const std::string& s_str() const; - const char* c_str() const noexcept; - size_t length() const noexcept; - bool has_length(int len) const noexcept; - bool has_length(int min, int max) const noexcept; - int to_int() const; - float to_float() const; - void clear() noexcept; - bool empty() const noexcept; - bool is_number() const noexcept; - t_string to_upper() const; - t_string to_lower() const; - t_string trim() const; - t_string skip(int count) const; - t_string remove_first(int count = 1) const; - t_string remove_last(int count = 1) const; - t_string remove_first_and_last(int count = 1) const; - t_string get_first(int count) const; - t_string get_last(int count) const; - t_list split(char delim, bool trim_tokens) const; - t_list split_chunks(int chunk_size) const; - t_string substr(int first) const; - t_string substr(int first, int last) const; - t_string replace(const t_string& original, const t_string& replacement) const; - t_string replace(const char& original, const char& replacement) const; - t_string remove_all(const t_string& chars) const; - t_string reverse() const; - bool starts_with(const t_string& prefix) const; - bool ends_with(const t_string& suffix) const; - bool starts_and_ends_with(const t_string& prefix, const t_string& suffix) const; - bool starts_and_ends_with(const t_string& same_preffix_and_suffix) const; - bool contains(const t_string& other) const; - bool contains_only(const t_string& chars) const; - bool contains_any(const t_string& chars) const; - bool in(const t_list& strings) const; - int index_of(const t_string& str) const; - int last_index_of(const t_string& str) const; - t_list find_all(const char& ch, size_t offset = 0U); - int count(const char& ch); - -private: - static constexpr int fmt_buf_maxlen = 1024; - - std::string value; -}; - -namespace std -{ - template<> - struct hash { - size_t operator()(const t_string& wrapper) const { - return hash{}(wrapper.s_str()); - } - }; -} diff --git a/0.4A/PTM/t_subsystem.cpp b/0.4A/PTM/t_subsystem.cpp deleted file mode 100644 index a6a48c5..0000000 --- a/0.4A/PTM/t_subsystem.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "t_subsystem.h" - -t_subsystem::t_subsystem() -{ -} - -t_subsystem::~t_subsystem() -{ -} - -bool t_subsystem::is_active() const -{ - return active; -} - -void t_subsystem::activate() -{ - active = true; -} - -void t_subsystem::deactivate() -{ - active = false; -} diff --git a/0.4A/PTM/t_subsystem.h b/0.4A/PTM/t_subsystem.h deleted file mode 100644 index e2b3a39..0000000 --- a/0.4A/PTM/t_subsystem.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once -#include "t_keyboard.h" - -class t_subsystem -{ -public: - t_subsystem(); - virtual ~t_subsystem(); - - virtual void on_draw() = 0; - virtual void on_keydown(t_keycode& key, t_keymod& mod) = 0; - - bool is_active() const; - void activate(); - void deactivate(); - -private: - bool active = false; -}; diff --git a/0.4A/PTM/t_sys_test.cpp b/0.4A/PTM/t_sys_test.cpp deleted file mode 100644 index f2514ee..0000000 --- a/0.4A/PTM/t_sys_test.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include "t_sys_test.h" -#include "t_ptm.h" - -void t_sys_test::on_draw() -{ - int x = ptm.mouse.get_x(); - int y = ptm.mouse.get_y(); - bool left = ptm.mouse.btn_left(); - bool middle = ptm.mouse.btn_middle(); - bool right = ptm.mouse.btn_right(); - - ptm.scr.set_backcolor(0x000080); - ptm.scr.print(t_string::fmt("%i, %i | %i, %i, %i", - x, y, left, middle, right), 1, 1, 0xffffff); -} - -void t_sys_test::on_keydown(t_keycode& key, t_keymod& mod) -{ -} diff --git a/0.4A/PTM/t_sys_test.h b/0.4A/PTM/t_sys_test.h deleted file mode 100644 index 63cdbf2..0000000 --- a/0.4A/PTM/t_sys_test.h +++ /dev/null @@ -1,8 +0,0 @@ -#pragma once -#include "t_subsystem.h" - -class t_sys_test : public t_subsystem -{ - void on_draw() override; - void on_keydown(t_keycode& key, t_keymod& mod) override; -}; diff --git a/0.4A/PTM/t_system.cpp b/0.4A/PTM/t_system.cpp deleted file mode 100644 index 2ad7a55..0000000 --- a/0.4A/PTM/t_system.cpp +++ /dev/null @@ -1,87 +0,0 @@ -#include "t_system.h" -#include "t_ptm.h" -#include "t_main_window.h" -#include "t_screen.h" -#include "t_charset.h" -#include "t_image.h" -#include "t_color.h" -#include "t_subsystem.h" - -t_system::t_system() -{ - SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO); - - add_subsystem(&sys_test); - - sys_test.activate(); -} - -t_system::~t_system() -{ - for (int i = 0; i < subsystems.size(); i++) - subsystems[i] = nullptr; - - subsystems.clear(); - - quit(); - SDL_Quit(); -} - -void t_system::add_subsystem(t_subsystem* sys) -{ - subsystems.push_back(sys); -} - -void t_system::quit() -{ - ptm.wnd.close(); -} - -int t_system::run() -{ - ptm.wnd.open(ptm.defaults.wnd_title, - ptm.defaults.wnd_buffer_w, ptm.defaults.wnd_buffer_h, - ptm.defaults.wnd_stretch_w, ptm.defaults.wnd_stretch_h); - - ptm.scr.set_backcolor(ptm.defaults.back_color); - - while (ptm.wnd.is_open()) { - - ptm.scr.clear(); - on_draw(); - ptm.scr.update(); - - SDL_Event event; - SDL_PollEvent(&event); - - if (event.type == SDL_EVENT_QUIT) - quit(); - else if (event.type == SDL_EVENT_KEY_DOWN) - on_keydown(event.key.key, event.key.mod); - } - - return 0; -} - -void t_system::on_draw() -{ - for (auto& sys : subsystems) { - if (sys->is_active()) { - sys->on_draw(); - } - } -} - -void t_system::on_keydown(t_keycode& key, t_keymod& mod) -{ - if (key == SDLK_RETURN && ptm.kb.alt()) { - ptm.scr.toggle_fullscreen(); - } - else { - for (auto& sys : subsystems) { - if (sys->is_active()) { - sys->on_keydown(key, mod); - } - } - } -} diff --git a/0.4A/PTM/t_system.h b/0.4A/PTM/t_system.h deleted file mode 100644 index 908f1e2..0000000 --- a/0.4A/PTM/t_system.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once -#include "t_keyboard.h" -#include "t_list.h" -#include "t_sys_test.h" - -class t_subsystem; - -class t_system -{ -public: - t_sys_test sys_test; - - t_system(); - ~t_system(); - - int run(); - void quit(); - -private: - t_list subsystems; - - void add_subsystem(t_subsystem* sys); - - void on_draw(); - void on_keydown(t_keycode& key, t_keymod& mod); -}; diff --git a/0.4A/PTM/t_tile.cpp b/0.4A/PTM/t_tile.cpp deleted file mode 100644 index 1aa0d5e..0000000 --- a/0.4A/PTM/t_tile.cpp +++ /dev/null @@ -1,53 +0,0 @@ -#include "t_tile.h" -#include "t_ptm.h" -#include "t_image.h" -#include "t_screen.h" - -t_tile::t_tile() -{ - set_empty(); -} - -t_tile::~t_tile() -{ - set_empty(); -} - -void t_tile::set_image(t_index img_index) -{ - image_index = img_index; -} - -t_index t_tile::get_image() const -{ - return image_index; -} - -void t_tile::remove_image() -{ - image_index = ptm.invalid_index; -} - -bool t_tile::has_image() const -{ - return image_index != ptm.invalid_index; -} - -bool t_tile::empty() const -{ - return data.empty() && code.empty() && !has_image(); -} - -void t_tile::set_empty() -{ - data.clear(); - remove_image(); - reset_flags(); -} - -void t_tile::reset_flags() -{ - enabled = true; - visible = true; - solid = false; -} diff --git a/0.4A/PTM/t_tile.h b/0.4A/PTM/t_tile.h deleted file mode 100644 index 826e6d9..0000000 --- a/0.4A/PTM/t_tile.h +++ /dev/null @@ -1,30 +0,0 @@ -#pragma once -#include "t_string.h" -#include "t_index.h" -#include "t_data.h" - -class t_screen; - -class t_tile -{ -public: - t_data data; - t_string code; - bool enabled = true; - bool visible = true; - bool solid = false; - - t_tile(); - ~t_tile(); - - void set_image(t_index img_index); - t_index get_image() const; - void remove_image(); - bool has_image() const; - bool empty() const; - void set_empty(); - void reset_flags(); - -private: - t_index image_index; -}; diff --git a/0.4A/PTM/t_util.cpp b/0.4A/PTM/t_util.cpp deleted file mode 100644 index 1c90418..0000000 --- a/0.4A/PTM/t_util.cpp +++ /dev/null @@ -1,234 +0,0 @@ -#include -#include -#include -#include -#include "t_util.h" - -static std::random_device rd; -static std::mt19937 mt(rd()); - -int t_util::rnd(int max) -{ - return std::uniform_int_distribution(0, max)(mt); -} - -int t_util::rnd(int min, int max) -{ - return std::uniform_int_distribution(min, max)(mt); -} - -int t_util::rnd_byte() -{ - return rnd(0, 255); -} - -t_string t_util::rnd_hex(int bytes) -{ - std::stringstream ss; - - for (auto i = 0; i < bytes; i++) { - auto rc = rnd_byte(); - std::stringstream hexstream; - hexstream << std::hex << int(rc); - auto hex = hexstream.str(); - ss << (hex.length() < 2 ? '0' + hex : hex); - } - - return ss.str(); -} - -t_string t_util::rnd_string(int length) -{ - return rnd_string(length, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"); -} - -t_string t_util::rnd_string(int length, const t_string& alphabet) -{ - std::stringbuf sb; - - for (auto i = 0; i < length; i++) { - char ch = alphabet[rnd((int)alphabet.length()) - 1]; - sb.sputc(ch); - } - - return sb.str(); - -} - -bool t_util::chance(int rate) -{ - if (rate >= 100) - return true; - if (rate > 0) - return rnd(100) <= rate; - - return false; -} - -int t_util::percent(int value, int percentage) -{ - return value * percentage / 100; -} - -void t_util::int_to_bytes(uint32_t val, uint8_t bytes[4]) -{ - uint32_t uval = val; - bytes[0] = uval; - bytes[1] = uval >> 8; - bytes[2] = uval >> 16; - bytes[3] = uval >> 24; -} - -uint32_t t_util::bytes_to_int(uint8_t bytes[4]) -{ - uint32_t u0 = bytes[0], u1 = bytes[1], u2 = bytes[2], u3 = bytes[3]; - uint32_t uval = u0 | (u1 << 8) | (u2 << 16) | (u3 << 24); - return uval; -} - -void t_util::short_to_bytes(uint16_t val, uint8_t bytes[2]) -{ - uint8_t int_bytes[4]; - int_to_bytes(val, int_bytes); - bytes[0] = int_bytes[0]; - bytes[1] = int_bytes[1]; -} - -uint16_t t_util::bytes_to_short(uint8_t bytes[2]) -{ - uint8_t int_bytes[4]; - int_bytes[0] = bytes[0]; - int_bytes[1] = bytes[1]; - return bytes_to_int(int_bytes); -} - -uint32_t t_util::wrap_add(uint32_t val, int dx, const uint32_t lower, const uint32_t upper) -{ - while (dx < 0) { - if (val == lower) - val = upper; - else - --val; - ++dx; - } - while (dx > 0) { - if (val == upper) - val = lower; - else - ++val; - --dx; - } - return val; -} - -int t_util::get_digit_count(uint32_t number) -{ - return number > 0 ? (int)log10((double)number) + 1 : 1; -} - -t_string t_util::xor_encrypt(const t_string& str, char xor_key) -{ - std::string encrypted = str; - - for (int i = 0; i < str.length(); i++) - encrypted[i] = str[i] ^ xor_key; - - return encrypted; -} - -t_string t_util::xor_decrypt(const t_string& str, char xor_key) -{ - return xor_encrypt(str, xor_key); -} - -t_string t_util::size_to_string(uint64_t bytes) -{ - const char* suffix[] = { "B", "KB", "MB", "GB", "TB" }; - const char length = sizeof(suffix) / sizeof(suffix[0]); - - int i = 0; - double dblBytes = (double)bytes; - - if (bytes > 1024) { - for (i = 0; (bytes / 1024) > 0 && i < length - 1; i++, bytes /= 1024) - dblBytes = bytes / 1024.0; - } - - char output[100]; - sprintf_s(output, "%.02lf %s", dblBytes, suffix[i]); - return output; -} - -t_string t_util::datetime(const t_string& format) -{ - auto now = std::chrono::system_clock::now(); - auto in_time_t = std::chrono::system_clock::to_time_t(now); - - std::stringstream ss; - ss << std::put_time(std::localtime(&in_time_t), format.c_str()); - return ss.str(); -} - -t_string t_util::datetime() -{ - return datetime("%Y-%m-%d %H:%M:%S"); -} - -t_string t_util::date() -{ - return datetime("%Y-%m-%d"); -} - -t_string t_util::time() -{ - return datetime("%H:%M:%S"); -} - -void t_util::set_clipboard(const t_string& text) -{ - bool ok = OpenClipboard(nullptr); - if (ok) { - ok = EmptyClipboard(); - const char* text_chars = text.c_str(); - int length = (int)strlen(text_chars); - HGLOBAL clipboard_data = GlobalAlloc(GMEM_MOVEABLE, length + 1); - if (clipboard_data != nullptr) { - char* text_chars_copy = (char*)GlobalLock(clipboard_data); - if (text_chars_copy != nullptr) { - strcpy_s(text_chars_copy, length, LPCSTR(text_chars)); - } - GlobalUnlock(clipboard_data); - SetClipboardData(CF_TEXT, clipboard_data); - } - ok = CloseClipboard(); - } -} - -t_string t_util::get_clipboard() -{ - bool ok = OpenClipboard(nullptr); - if (ok) { - HANDLE clipboard_data = GetClipboardData(CF_TEXT); - char* text_chars = (char*)GlobalLock(clipboard_data); - if (text_chars != nullptr) { - std::string text(text_chars); - GlobalUnlock(clipboard_data); - return text; - } - } - return ""; -} - -int t_util::distance(int x1, int y1, int x2, int y2) -{ - int delta_x = x2 - x1; - int delta_y = y2 - y1; - return static_cast(std::round(std::sqrt(delta_x * delta_x + delta_y * delta_y))); -} - -float t_util::distance(float x1, float y1, float x2, float y2) -{ - float delta_x = x2 - x1; - float delta_y = y2 - y1; - return std::sqrt(delta_x * delta_x + delta_y * delta_y); -} diff --git a/0.4A/PTM/t_util.h b/0.4A/PTM/t_util.h deleted file mode 100644 index bad4ed2..0000000 --- a/0.4A/PTM/t_util.h +++ /dev/null @@ -1,32 +0,0 @@ -#pragma once -#include "t_string.h" - -class t_util -{ -public: - static int rnd(int max); - static int rnd(int min, int max); - static int rnd_byte(); - static t_string rnd_hex(int bytes); - static t_string rnd_string(int length); - static t_string rnd_string(int length, const t_string& alphabet); - static bool chance(int rate); - static int percent(int value, int percentage); - static void int_to_bytes(uint32_t val, uint8_t bytes[4]); - static uint32_t bytes_to_int(uint8_t bytes[4]); - static void short_to_bytes(uint16_t val, uint8_t bytes[2]); - static uint16_t bytes_to_short(uint8_t bytes[2]); - static uint32_t wrap_add(uint32_t val, int dx, const uint32_t lower, const uint32_t upper); - static int get_digit_count(uint32_t number); - static t_string xor_encrypt(const t_string& str, char xor_key); - static t_string xor_decrypt(const t_string& str, char xor_key); - static t_string size_to_string(uint64_t bytes); - static t_string datetime(const t_string& format); - static t_string datetime(); - static t_string date(); - static t_string time(); - static void set_clipboard(const t_string& text); - static t_string get_clipboard(); - static int distance(int x1, int y1, int x2, int y2); - static float distance(float x1, float y1, float x2, float y2); -}; diff --git a/0.4A/build/PTM.exe b/0.4A/build/PTM.exe deleted file mode 100644 index edd719a..0000000 Binary files a/0.4A/build/PTM.exe and /dev/null differ diff --git a/0.4A/build/SDL3.dll b/0.4A/build/SDL3.dll deleted file mode 100644 index a57702f..0000000 Binary files a/0.4A/build/SDL3.dll and /dev/null differ