Skip to content

Commit

Permalink
Merge pull request #6 from pzaino/develop
Browse files Browse the repository at this point in the history
added Makefiles and fixed a bunch of issues with code quality
  • Loading branch information
pzaino authored Mar 1, 2024
2 parents 69427cd + b0d61f4 commit 00e8cdb
Show file tree
Hide file tree
Showing 12 changed files with 581 additions and 126 deletions.
38 changes: 38 additions & 0 deletions MkGCC,fd7
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
| Generic Library builder for GCC on RISC OS
| by Paolo Fabio Zaino

echo ++++++++++++++++++++++++
echo ++ Building using GCC ++
echo ++++++++++++++++++++++++

Set Build$Root <Obey$Dir>

WimpSlot -min 28672K

echo ---------------------
echo Building the Library:
echo ---------------------

Dir <Build$Root>.src
IfThere @.UltimaVM.o.* Then wipe @.UltimaVM.o.* ~C ~V
make all THROWBACK=-throwback OS=RISC_OS -f MakeFileGCC

|IFthere @.o.ezinilib Then copy @.o.libezini @.^.!LibEzINI.a.libezini ~C N
|IFthere @.h.ezini Then copy @.h.ezini @.^.!LibEzINI.h.ezini ~C N

echo
echo ---------------------
echo

echo ---------------------
echo Building Tests:
echo ---------------------

Dir <Build$Root>.tests
make all THROWBACK=-throwback -f MakeFileGCC

echo
echo ---------------------
echo

Dir <Build$Root>
6 changes: 6 additions & 0 deletions MkGCCClean,fd7
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Dir <Obey$Dir>.src
WimpSlot -min 16384K
make clean -f MakeFileGCC



64 changes: 64 additions & 0 deletions src/MakefileGCC
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# MicroFB - A simple Framebuffer library for RISC OS
# (c) 2024 by Paolo Fabio Zaino, all rights reserved
# Licensed under the CDDL v1.1 License

CC = g++
PTHREAD = -pthread
EXT_SYM = .
CFLAGS_BASE = -Wall -Wextra -pedantic -std=gnu++11 -O2
LDFLAGS_EXTRA =
extras =
server =
client =

LIB_NAME = MicroFB
LIB_SOURCES = fb.cpp layer.cpp render_strategy.cpp
LIB_OBJECTS = $(LIB_SOURCES:.cpp=.o)
LIB_OUT = lib$(LIB_NAME)$(EXT_SYM)a
LIB_LINK = -L./ -l$(LIB_NAME)

ifeq ($(OS), RISC_OS)
CC = g++
# PTHREAD = -lpthread
PTHREAD =
EXT_SYM =.
CFLAGS_BASE = -Wall -Wextra -pedantic -std=gnu++11
LDFLAGS_EXTRA = -lgcc -lstdlib_extras
#extras = stdlib_extras
LIB_LINK = -l$(LIB_NAME)
endif
ifeq ($(OS), Darwin)
CC = /opt/homebrew/bin/g++-13
PTHREAD = -pthread
LIB_LINK = $(LIB_OUT)
endif

CFLAGS = $(CFLAGS_BASE) $(PTHREAD)


all: $(LIB_OUT) $(server) $(client)

# Pre-GCC 4.8.1 compatibility
stdlib_extras: stdlib_extras.cpp
$(CC) $(CFLAGS) -o stdlib_extras.o -c stdlib_extras.cpp
ar rcs libstdlib_extras.a stdlib_extras.o

# Library compilation
$(LIB_OUT): $(LIB_OBJECTS)
ar rcs $(LIB_OUT) $(LIB_OBJECTS)

$(LIB_OBJECTS): $(LIB_SOURCES)
$(CC) $(CFLAGS) -c $(LIB_SOURCES)

# Server executable
#$(server): Server.cpp $(LIB_OUT) $(extras)
# $(CC) $(CFLAGS) -o $(server) Server.cpp $(LIB_LINK) $(LDFLAGS_EXTRA)

# Client executable
#$(client): Client.cpp $(LIB_OUT) $(extras)
# $(CC) $(CFLAGS) -o $(client) Client.cpp $(LIB_LINK) $(LDFLAGS_EXTRA)

.PHONY: clean

clean:
rm -f $(LIB_OBJECTS) $(LIB_OUT) $(server) $(client)
8 changes: 4 additions & 4 deletions src/MkGCC.sh
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# This is a special file that will be used to control automated code
# analysis tools such as SonarQube, Coverity, etc. on GitHub.
# This file is not meant to be executed by humans, but by automated
# tools.
# tools.
# If you want to build the project, please use the MkGCC (note no .sh)
# script instead or MkDDE on RISC OS.

# MAKE SURE this file is calling your MakefileGCC with the correct
# MAKE SURE this file is calling your MakefileGCC with the correct
# target and make sure your MakefileGCC uses the variable OS to
# determine the target OS.
# determine the target OS.

current_dir="$1"
if [ "$current_dir" == "" ]; then
Expand All @@ -21,4 +21,4 @@ cd ${current_dir}
cat ${current_dir}/MakeFileGCC

# Make the artifacts
make static OS=`uname -s` -f ${current_dir}/MakefileGCC
make all OS=`uname -s` -f ${current_dir}/MakefileGCC
60 changes: 44 additions & 16 deletions src/cpp/fb
Original file line number Diff line number Diff line change
@@ -1,35 +1,54 @@
/*
* This file is part of:
* This file is part of:
* MicroFB, a minimal framebuffer library for RISC OS
*
* Description:
* Description:
* This project aims to provide a simple and efficient way to manage
* the framebuffer on RISC OS using C++11. It abstracts the direct
* interaction with the GraphicsV API, offering a higher-level
* the framebuffer on RISC OS using C++11. It abstracts the direct
* interaction with the GraphicsV API, offering a higher-level
* interface for drawing operations and framebuffer manipulation.
*
* Author:
* Paolo Fabio Zaino, all rights reserved.
* Distributed under License:
* CDDL v1.1 (Common Development and Distribution License Version
* 1.1) The use of this project is subject to the terms of the
* CDDL v1.1. This project can be used and distributed according
* to the terms of this license. For details on the CDDL v1.1,
* Distributed under License:
* CDDL v1.1 (Common Development and Distribution License Version
* 1.1) The use of this project is subject to the terms of the
* CDDL v1.1. This project can be used and distributed according
* to the terms of this license. For details on the CDDL v1.1,
* please refer to the official license documentation.
*/

#include "fb.hpp"
#include "layer.hpp"
#include <stdexcept>
#include <memory> // For std::shared_ptr

// Include MicroFB libraries
#include "common.h"
#if GCC_VERSION < 50000
// Include my own C++ STDLib extras for compatibility with older GCC versions
//#include "stdlib_extras.h"
#endif
#include "fb.h"
#include "layer.h"

// Constructor
FrameBuffer::FrameBuffer(unsigned int width, unsigned int height, std::shared_ptr<RenderStrategy> strategy)
: width(width), height(height), renderStrategy(strategy) {}
FrameBuffer::FrameBuffer(unsigned int h_dim, unsigned int v_dim, std::shared_ptr<RenderStrategy> strategy)
: renderStrategy(strategy), width(h_dim), height(v_dim) {}

// Add a layer to the framebuffer
void FrameBuffer::addLayer(const Layer& layer) {
void FrameBuffer::addLayer(const std::shared_ptr<Layer>& layer) {
layers.push_back(layer);
}

// Add a layer to the framebuffer
void FrameBuffer::addLayer(std::shared_ptr<Layer>&& layer) {
layers.push_back(std::move(layer));
}

// Add a layer to the framebuffer
void FrameBuffer::addLayer() {
layers.push_back(std::make_shared<Layer>(width, height, renderStrategy, currentMemoryManager));
}

// Remove a layer from the framebuffer by index
void FrameBuffer::removeLayer(size_t index) {
if (index < layers.size()) {
Expand All @@ -38,7 +57,7 @@ void FrameBuffer::removeLayer(size_t index) {
}

// Accessor for layer by index
Layer& FrameBuffer::getLayer(size_t index) {
std::shared_ptr<Layer> FrameBuffer::getLayer(size_t index) const {
// Simple bounds checking, throw std::out_of_range if index is invalid
if (index >= layers.size()) {
throw std::out_of_range("Layer index is out of range.");
Expand All @@ -51,7 +70,16 @@ void FrameBuffer::setRenderStrategy(std::shared_ptr<RenderStrategy> strategy) {
renderStrategy = strategy;
// Update the render strategy for all existing layers
for (auto& layer : layers) {
layer.setRenderStrategy(renderStrategy);
layer->setRenderStrategy(renderStrategy);
}
}

// Set the memory manager for the framebuffer and all its layers
void FrameBuffer::setMemoryManager(std::shared_ptr<MemoryManager> manager) {
currentMemoryManager = manager;
// Update the memory manager for all existing layers
for (auto& layer : layers) {
layer->setMemoryManager(currentMemoryManager);
}
}

Expand Down
94 changes: 57 additions & 37 deletions src/cpp/layer
Original file line number Diff line number Diff line change
@@ -1,103 +1,123 @@
/*
* This file is part of:
* This file is part of:
* MicroFB, a minimal framebuffer library for RISC OS
*
* Description:
* Description:
* This project aims to provide a simple and efficient way to manage
* the framebuffer on RISC OS using C++11. It abstracts the direct
* interaction with the GraphicsV API, offering a higher-level
* the framebuffer on RISC OS using C++11. It abstracts the direct
* interaction with the GraphicsV API, offering a higher-level
* interface for drawing operations and framebuffer manipulation.
*
* Author:
* Paolo Fabio Zaino, all rights reserved.
* Distributed under License:
* CDDL v1.1 (Common Development and Distribution License Version
* 1.1) The use of this project is subject to the terms of the
* CDDL v1.1. This project can be used and distributed according
* to the terms of this license. For details on the CDDL v1.1,
* Distributed under License:
* CDDL v1.1 (Common Development and Distribution License Version
* 1.1) The use of this project is subject to the terms of the
* CDDL v1.1. This project can be used and distributed according
* to the terms of this license. For details on the CDDL v1.1,
* please refer to the official license documentation.
*/

#include <memory> // For std::shared_ptr

#include "mem_manager.hpp"
#include "layer.hpp"
// Include MicroFB libraries
#include "common.h"
#if GCC_VERSION < 50000
// Include my own C++ STDLib extras for compatibility with older GCC versions
//#include "stdlib_extras.h"
#endif
#include "mem_manager.h"
#include "layer.h"

// Constructor implementation
Layer::Layer(pixel_t width, pixel_t height, std::shared_ptr<RenderStrategy> strategy)
: width(width), height(height), opacity(1.0f), visible(true), currentRenderStrategy(strategy) {

Layer::Layer(pixel_t width, pixel_t height, std::shared_ptr<RenderStrategy> strategy, std::shared_ptr<MemoryManager> currMemoryManager)
: currentRenderStrategy(strategy), opacity(1.0f), visible(true), width(width), height(height) {

if (currentMemoryManager == nullptr) {
currentMemoryManager = currMemoryManager;
}

// Initialize pixel buffer with default color (0)
pixels = static_cast<color_t*>(memoryManager->allocate(width * height * sizeof(color_t)));
pixels = static_cast<color_t*>(currentMemoryManager->allocate(width * height * sizeof(color_t)));

}

// Destructor implementation
Layer::~Layer() {
// Not much for now
}

// Set the render strategy
void Layer::setRenderStrategy(std::shared_ptr<RenderStrategy> strategy) {
currentRenderStrategy = strategy; // Set the render strategy
}

// Set the memory manager
void Layer::setMemoryManager(std::shared_ptr<MemoryManager> manager) {
currentMemoryManager = manager; // Set the memory manager
}

// Clear the layer with a specific color
void Layer::clear(color_t color) {
currentRenderStrategy->clear(pixels, color); // Use the render strategy to clear the layer
currentRenderStrategy->clear(*this, color); // Use the render strategy to clear the layer
}

// Direct pixel manipulation
void Layer::setPixel(pixel_t x, pixel_t y, color_t color) {
currentRenderStrategy->setPixel(pixels, x, y, color); // Use the render strategy to set the pixel
currentRenderStrategy->setPixel(*this, x, y, color); // Use the render strategy to set the pixel
}

// Draw a line
void Layer::drawLine(pixel_t x1, pixel_t y1, pixel_t x2, pixel_t y2, color_t color) {
currentRenderStrategy->drawLine(pixels, x1, y1, x2, y2, color); // Use the render strategy to draw the line
currentRenderStrategy->drawLine(*this, x1, y1, x2, y2, color); // Use the render strategy to draw the line
}

// Draw a rectangle
void Layer::drawRect(pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color) {
currentRenderStrategy->drawRect(pixels, x, y, w, h, color); // Use the render strategy to draw the rectangle
currentRenderStrategy->drawRect(*this, x, y, w, h, color); // Use the render strategy to draw the rectangle
}

// Fill a rectangle
void Layer::fillRect(pixel_t x, pixel_t y, pixel_t w, pixel_t h, color_t color) {
currentRenderStrategy->fillRect(pixels, x, y, w, h, color); // Use the render strategy to fill the rectangle
currentRenderStrategy->fillRect(*this, x, y, w, h, color); // Use the render strategy to fill the rectangle
}

// Draw a circle
// Draw a circle
void Layer::drawCircle(pixel_t x, pixel_t y, pixel_t r, color_t color) {
currentRenderStrategy->drawCircle(pixels, x, y, r, color); // Use the render strategy to draw the circle
currentRenderStrategy->drawCircle(*this, x, y, r, color); // Use the render strategy to draw the circle
}

// Fill a circle
// Fill a circle
void Layer::fillCircle(pixel_t x, pixel_t y, pixel_t r, color_t color) {
currentRenderStrategy->fillCircle(pixels, x, y, r, color); // Use the render strategy to fill the circle
currentRenderStrategy->fillCircle(*this, x, y, r, color); // Use the render strategy to fill the circle
}

// Draw an ellipse
// Draw an ellipse
void Layer::drawEllipse(pixel_t x, pixel_t y, pixel_t rx, pixel_t ry, color_t color) {
currentRenderStrategy->drawEllipse(pixels, x, y, rx, ry, color); // Use the render strategy to draw the ellipse
currentRenderStrategy->drawEllipse(*this, x, y, rx, ry, color); // Use the render strategy to draw the ellipse
}

// Fill an ellipse
// Fill an ellipse
void Layer::fillEllipse(pixel_t x, pixel_t y, pixel_t rx, pixel_t ry, color_t color) {
currentRenderStrategy->fillEllipse(pixels, x, y, rx, ry, color); // Use the render strategy to fill the ellipse
currentRenderStrategy->fillEllipse(*this, x, y, rx, ry, color); // Use the render strategy to fill the ellipse
}

// Draw a polygon
// Draw a polygon
void Layer::drawPolygon(const std::vector<pixel_t>& points, color_t color) {
currentRenderStrategy->drawPolygon(pixels, points, color); // Use the render strategy to draw the polygon
currentRenderStrategy->drawPolygon(*this, points, color); // Use the render strategy to draw the polygon
}

// Fill a polygon
// Fill a polygon
void Layer::fillPolygon(const std::vector<pixel_t>& points, color_t color) {
currentRenderStrategy->fillPolygon(pixels, points, color); // Use the render strategy to fill the polygon
currentRenderStrategy->fillPolygon(*this, points, color); // Use the render strategy to fill the polygon
}

// Draw text
// Draw text
void Layer::drawText(pixel_t x, pixel_t y, const char* text, color_t color) {
currentRenderStrategy->drawText(pixels, x, y, text, color); // Use the render strategy to draw the text
currentRenderStrategy->drawText(*this, x, y, text, color); // Use the render strategy to draw the text
}

// Draw an image
// Draw an image
void Layer::drawImage(pixel_t x, pixel_t y, const Layer& image) {
currentRenderStrategy->drawImage(pixels, x, y, image); // Use the render strategy to draw the image
currentRenderStrategy->drawImage(*this, x, y, image); // Use the render strategy to draw the image
}
Loading

0 comments on commit 00e8cdb

Please sign in to comment.