Skip to content

Commit

Permalink
View history
Browse files Browse the repository at this point in the history
  • Loading branch information
FernandoAiresCastello committed Jun 16, 2024
1 parent 078bac8 commit c7bf13b
Show file tree
Hide file tree
Showing 24 changed files with 171 additions and 415 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ temp.ptm
fernando/
v0.3b/Build/files/main.ptm
v0.4b/temp/
cppcheck
Binary file modified v0.4b/build/PTM.exe
Binary file not shown.
17 changes: 17 additions & 0 deletions v0.4b/ptm.cppcheck
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="1">
<builddir>cppcheck</builddir>
<importproject>PTM.sln</importproject>
<analyze-all-vs-configs>false</analyze-all-vs-configs>
<check-headers>true</check-headers>
<check-unused-templates>true</check-unused-templates>
<max-ctu-depth>2</max-ctu-depth>
<max-template-recursion>100</max-template-recursion>
<vs-configurations>
<config>Debug</config>
</vs-configurations>
<libraries>
<library>sdl</library>
</libraries>
<project-name>ptm</project-name>
</project>
26 changes: 13 additions & 13 deletions v0.4b/src/PTM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,15 @@ namespace ptm
t_screen scr;
}

void ptm::init()
{
wnd.open(wnd_title, wnd_size);

scr.set_window(&wnd);
scr.set_charset(&chr);
scr.set_palette(&pal);
}

void ptm::run_tests()
{
t_tests tests;
Expand All @@ -24,24 +33,18 @@ void ptm::run_tests()

void ptm::run_graphics_test()
{
wnd.open(wnd_title, wnd_size);

t_tilebuffer tilebuf;
tilebuf.clear();
tilebuf.set_text("Hello World!", 1, 20, 15, 0);

int i = 0;
for (int y = 1; y < 1 + 16; y++) {
for (int x = 1; x < 1 + 16; x++) {
tilebuf.set(t_tile(0, i, i), x, y);
scr.put(t_tile(0, i, i), x, y);
i++;
}
}

i = 0;
for (int y = 1; y < 1 + 16; y++) {
for (int x = 20; x < 20 + 16; x++) {
tilebuf.set(t_tile(i, 15, 0), x, y);
scr.put(t_tile(i, 15, 0), x, y);
i++;
}
}
Expand All @@ -51,11 +54,8 @@ void ptm::run_graphics_test()

void ptm::run_main()
{
wnd.open(wnd_title, wnd_size);

scr.set_window(&wnd);
scr.set_charset(&chr);
scr.set_palette(&pal);
scr.color(0x3a, 0x38, 0x31);
scr.print("Hello World!", 0, 0);

halt();
}
Expand Down
1 change: 1 addition & 0 deletions v0.4b/src/PTM.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace ptm
const t_string wnd_title = "PTM - Programmable Tile Machine";
const int wnd_size = 3;

void init();
void run_tests();
void run_graphics_test();
void run_main();
Expand Down
1 change: 1 addition & 0 deletions v0.4b/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

int main(int argc, char* argv[])
{
ptm::init();
ptm::run_tests();
//ptm::run_graphics_test();
ptm::run_main();
Expand Down
263 changes: 2 additions & 261 deletions v0.4b/src/t_charset.cpp

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions v0.4b/src/t_charset.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class t_charset
t_charset& operator=(const t_charset& other);

void remove_all();
void add(t_binary bits);
void add(const t_binary& bits);
t_binary& get(t_index index);
void set(t_index index, t_binary bits);
void set(t_index index, const t_binary& bits);
int size() const;
void reset();

Expand Down
24 changes: 9 additions & 15 deletions v0.4b/src/t_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,8 @@ t_data::t_data()
{
}

t_data::t_data(const t_data& other)
t_data::t_data(const t_data& other) : entries(other.entries)
{
entries = other.entries;
}

t_data::~t_data()
{
entries.clear();
}

bool t_data::operator==(const t_data& other) const
Expand Down Expand Up @@ -50,43 +44,43 @@ void t_data::clear()
entries.clear();
}

void t_data::set(t_string key, t_string value)
void t_data::set(const t_string& key, const t_string& value)
{
entries[key] = value;
}

void t_data::set(t_string key, int value)
void t_data::set(const t_string& key, int value)
{
entries[key] = std::to_string(value);
}

void t_data::remove(t_string key)
void t_data::remove(const t_string& key)
{
if (has(key))
entries.erase(key);
}

t_string t_data::get(t_string key)
t_string t_data::get(const t_string& key)
{
return has(key) ? entries[key] : t_data::null;
}

int t_data::get_int(t_string key)
int t_data::get_int(const t_string& key)
{
return has(key) ? entries[key].to_int() : t_data::null_int;
}

bool t_data::has(t_string key)
bool t_data::has(const t_string& key)
{
return entries.contains(key);
}

bool t_data::has(t_string key, t_string value)
bool t_data::has(const t_string& key, const t_string& value)
{
return has(key) && entries[key] == value;
}

bool t_data::has(t_string key, int value)
bool t_data::has(const t_string& key, int value)
{
return has(key) && entries[key].to_int() == value;
}
Expand Down
18 changes: 9 additions & 9 deletions v0.4b/src/t_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,22 @@ class t_data

t_data();
t_data(const t_data& other);
~t_data();
~t_data() = default;

bool operator==(const t_data& other) const;
t_data& operator=(const t_data& other);

bool is_empty() const;
bool is_not_empty() const;
void clear();
void set(t_string key, t_string value);
void set(t_string key, int value);
void remove(t_string key);
t_string get(t_string key);
int get_int(t_string key);
bool has(t_string key);
bool has(t_string key, t_string value);
bool has(t_string key, int value);
void set(const t_string& key, const t_string& value);
void set(const t_string& key, int value);
void remove(const t_string& key);
t_string get(const t_string& key);
int get_int(const t_string& key);
bool has(const t_string& key);
bool has(const t_string& key, const t_string& value);
bool has(const t_string& key, int value);
t_dict<t_string, t_string>& get_all();

private:
Expand Down
4 changes: 2 additions & 2 deletions v0.4b/src/t_palette.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void t_palette::remove_all()
colors.clear();
}

void t_palette::add(t_color color)
void t_palette::add(const t_color& color)
{
colors.emplace_back(color);
}
Expand All @@ -43,7 +43,7 @@ t_color& t_palette::get(t_index index)
return colors[index];
}

void t_palette::set(t_index index, t_color color)
void t_palette::set(t_index index, const t_color& color)
{
colors[index] = color;
}
Expand Down
4 changes: 2 additions & 2 deletions v0.4b/src/t_palette.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class t_palette
t_palette& operator=(const t_palette& other);

void remove_all();
void add(t_color color);
void add(const t_color& color);
t_color& get(t_index index);
void set(t_index index, t_color color);
void set(t_index index, const t_color& color);
int size() const;
void reset();

Expand Down
31 changes: 19 additions & 12 deletions v0.4b/src/t_screen.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
#include "t_screen.h"
#include "t_tilebuffer.h"

#define border_tile t_tile(0, border_color, border_color)

t_screen::t_screen()
{
buf = new t_tilebuffer(t_window::cols - 4, t_window::rows - 2);
buf_bdr = new t_tilebuffer();
buf = std::make_unique<t_tilebuffer>(t_window::cols - 4, t_window::rows - 2);
buf_bdr = std::make_unique<t_tilebuffer>();

for (int y = 0; y < t_window::rows; y++) {
for (int x = 0; x < t_window::cols; x++) {
for (int y = 0; y < buf->rows; y++) {
for (int x = 0; x < buf->cols; x++) {
buf->get_ref(x, y).flags.monochrome = true;
}
}

update_monochrome_tiles();
}
buf_bdr->fill(border_tile);

t_screen::~t_screen()
{
delete buf;
buf = nullptr;
delete buf_bdr;
buf_bdr = nullptr;
update_monochrome_tiles();
}

void t_screen::set_window(t_window* wnd)
Expand Down Expand Up @@ -65,9 +61,20 @@ void t_screen::color(t_index fgc, t_index bgc, t_index bdrc)
back_color = bgc;
border_color = bdrc;

buf_bdr->fill(border_tile);
update_monochrome_tiles();
}

void t_screen::put(const t_tile& tile, int x, int y)
{
buf->set(tile, x, y);
}

void t_screen::print(const t_string& str, int x, int y)
{
buf->set_text(str, x, y, fore_color, back_color);
}

void t_screen::update_monochrome_tiles()
{
for (int y = 0; y < buf->rows; y++) {
Expand Down
9 changes: 6 additions & 3 deletions v0.4b/src/t_screen.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#pragma once
#include <memory>
#include "t_window.h"
#include "t_index.h"

Expand All @@ -10,7 +11,7 @@ class t_screen
{
public:
t_screen();
~t_screen();
~t_screen() = default;

void set_window(t_window* wnd);
void set_charset(t_charset* chr);
Expand All @@ -19,13 +20,15 @@ class t_screen
void color(t_index fgc);
void color(t_index fgc, t_index bgc);
void color(t_index fgc, t_index bgc, t_index bdrc);
void put(const t_tile& tile, int x, int y);
void print(const t_string& str, int x, int y);

private:
t_window* wnd = nullptr;
t_charset* chr = nullptr;
t_palette* pal = nullptr;
t_tilebuffer* buf_bdr = nullptr;
t_tilebuffer* buf = nullptr;
std::unique_ptr<t_tilebuffer> buf_bdr;
std::unique_ptr<t_tilebuffer> buf;
t_index fore_color = 15;
t_index back_color = 1;
t_index border_color = 10;
Expand Down
Loading

0 comments on commit c7bf13b

Please sign in to comment.