Skip to content

Commit

Permalink
Add a new example, document both
Browse files Browse the repository at this point in the history
  • Loading branch information
XorTroll committed Dec 22, 2018
1 parent 918016d commit 8f51ad6
Show file tree
Hide file tree
Showing 7 changed files with 292 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Examples/LoopUpdating/Include/MainApplication.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

#pragma once

// Include Plutonium
#include <pu/Plutonium>

// Define your main layout as a class inheriting from pu::Layout
class Layout1 : public pu::Layout
{
public:
Layout1();
void Update();
private:
// An easy way to keep objects is to have them as private pointer members
pu::element::TextBlock *sampleText;
};

// Define your application as a class too
class MainApplication : public pu::Application
{
public:
MainApplication();
private:
// Layout instance
Layout1 *layout1;
};
201 changes: 201 additions & 0 deletions Examples/LoopUpdating/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,201 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------

ifeq ($(strip $(DEVKITPRO)),)
$(error "Please set DEVKITPRO in your environment. export DEVKITPRO=<path to>/devkitpro")
endif

TOPDIR ?= $(CURDIR)
include $(DEVKITPRO)/libnx/switch_rules

#---------------------------------------------------------------------------------
# TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed
# SOURCES is a list of directories containing source code
# DATA is a list of directories containing data files
# INCLUDES is a list of directories containing header files
# EXEFS_SRC is the optional input directory containing data copied into exefs, if anything this normally should only contain "main.npdm".
# ROMFS is the directory containing data to be added to RomFS, relative to the Makefile (Optional)
#
# NO_ICON: if set to anything, do not use icon.
# NO_NACP: if set to anything, no .nacp file is generated.
# APP_TITLE is the name of the app stored in the .nacp file (Optional)
# APP_AUTHOR is the author of the app stored in the .nacp file (Optional)
# APP_VERSION is the version of the app stored in the .nacp file (Optional)
# APP_TITLEID is the titleID of the app stored in the .nacp file (Optional)
# ICON is the filename of the icon (.jpg), relative to the project folder.
# If not set, it attempts to use one of the following (in this order):
# - <Project name>.jpg
# - icon.jpg
# - <libnx folder>/default_icon.jpg
#---------------------------------------------------------------------------------

APP_TITLE := Plutonium - Loop updating example
APP_AUTHOR := XorTroll
APP_VERSION := Test

# ICON := Icon.jpg
TARGET := LoopUpdating
BUILD := Build
SOURCES := Source
DATA := Bin
INCLUDES := Include
EXEFS_SRC := exefs_src
# ROMFS := RomFs

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE

CFLAGS := -g -O2 -fpermissive -ffunction-sections -w \
$(ARCH) $(DEFINES)

CFLAGS += $(INCLUDE) -D__SWITCH__

CXXFLAGS := $(CFLAGS) -fexceptions -std=gnu++17

ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=${DEVKITPRO}/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)

LIBS := -lpu -lfreetype -lSDL2_ttf -lSDL2_gfx -lSDL2_image -lSDL2 -lEGL -lGLESv2 -lglapi -ldrm_nouveau -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs` -lnx

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
# include and lib
#---------------------------------------------------------------------------------

# IMPORTANT! Change "$(CURDIR)/../../Plutonium/Output" to the path in which you have Plutonium libs.
LIBDIRS := $(PORTLIBS) $(LIBNX) $(CURDIR)/../../Plutonium/Output


#---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional
# rules for different file extensions
#---------------------------------------------------------------------------------
ifneq ($(BUILD),$(notdir $(CURDIR)))
#---------------------------------------------------------------------------------

export OUTPUT := $(CURDIR)/$(TARGET)
export TOPDIR := $(CURDIR)

export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
$(foreach dir,$(DATA),$(CURDIR)/$(dir))

export DEPSDIR := $(CURDIR)/$(BUILD)

CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))

#---------------------------------------------------------------------------------
# use CXX for linking C++ projects, CC for standard C
#---------------------------------------------------------------------------------
ifeq ($(strip $(CPPFILES)),)
#---------------------------------------------------------------------------------
export LD := $(CC)
#---------------------------------------------------------------------------------
else
#---------------------------------------------------------------------------------
export LD := $(CXX)
#---------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------

export OFILES_BIN := $(addsuffix .o,$(BINFILES))
export OFILES_SRC := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES := $(OFILES_BIN) $(OFILES_SRC)
export HFILES_BIN := $(addsuffix .h,$(subst .,_,$(BINFILES)))

export INCLUDE := $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) \
$(foreach dir,$(LIBDIRS),-I$(dir)/include) \
-I$(CURDIR)/$(BUILD)

export LIBPATHS := $(foreach dir,$(LIBDIRS),-L$(dir)/lib)

export BUILD_EXEFS_SRC := $(TOPDIR)/$(EXEFS_SRC)

ifeq ($(strip $(ICON)),)
icons := $(wildcard *.jpg)
ifneq (,$(findstring $(TARGET).jpg,$(icons)))
export APP_ICON := $(TOPDIR)/$(TARGET).jpg
else
ifneq (,$(findstring icon.jpg,$(icons)))
export APP_ICON := $(TOPDIR)/icon.jpg
endif
endif
else
export APP_ICON := $(TOPDIR)/$(ICON)
endif

ifeq ($(strip $(NO_ICON)),)
export NROFLAGS += --icon=$(APP_ICON)
endif

ifeq ($(strip $(NO_NACP)),)
export NROFLAGS += --nacp=$(CURDIR)/$(TARGET).nacp
endif

ifneq ($(APP_TITLEID),)
export NACPFLAGS += --titleid=$(APP_TITLEID)
endif

ifneq ($(ROMFS),)
export NROFLAGS += --romfsdir=$(CURDIR)/$(ROMFS)
endif

.PHONY: $(BUILD) clean all

#---------------------------------------------------------------------------------
all: $(BUILD)

$(BUILD):
@[ -d $@ ] || mkdir -p $@
@$(MAKE) --no-print-directory -C $(BUILD) -f $(CURDIR)/Makefile

#---------------------------------------------------------------------------------
clean:
@echo clean ...
@rm -fr $(BUILD) $(TARGET).pfs0 $(TARGET).nso $(TARGET).nro $(TARGET).nacp $(TARGET).elf


#---------------------------------------------------------------------------------
else
.PHONY: all

DEPENDS := $(OFILES:.o=.d)

#---------------------------------------------------------------------------------
# main targets
#---------------------------------------------------------------------------------
all : $(OUTPUT).pfs0 $(OUTPUT).nro

$(OUTPUT).pfs0 : $(OUTPUT).nso

$(OUTPUT).nso : $(OUTPUT).elf

ifeq ($(strip $(NO_NACP)),)
$(OUTPUT).nro : $(OUTPUT).elf $(OUTPUT).nacp
else
$(OUTPUT).nro : $(OUTPUT).elf
endif

$(OUTPUT).elf : $(OFILES)

$(OFILES_SRC) : $(HFILES_BIN)

#---------------------------------------------------------------------------------
# you need a rule like this for each extension you use as binary data
#---------------------------------------------------------------------------------
%.bin.o %_bin.h : %.bin
#---------------------------------------------------------------------------------
@echo $(notdir $<)
@$(bin2o)

-include $(DEPENDS)

#---------------------------------------------------------------------------------------
endif
#---------------------------------------------------------------------------------------
32 changes: 32 additions & 0 deletions Examples/LoopUpdating/Source/MainApplication.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <MainApplication.hpp>

// Implement all the layout/application functions here
// This variable needs to be global, but it can be a member of a class too (easier to define it here tho)
u32 count = 0;

Layout1::Layout1()
{
// Create the textblock (that text is a placeholder tho)
this->sampleText = new pu::element::TextBlock(300, 300, "Count: ");
// Add the textblock to the layout's element container. IMPORTANT! this MUST be done, having them as members is not enough (just a simple way to keep them)
this->AddChild(this->sampleText);
}

// This will be executed each loop, before rendering data
void Layout1::Update()
{
// Increase the number
count++;
// Update the number's text
this->sampleText->SetText("Count: " + std::to_string(count));
}

MainApplication::MainApplication()
{
// Create the layout (calling the constructor above)
this->layout1 = new Layout1();
// Add the loop function to the application via std::bind
this->AddThread(std::bind(&Layout1::Update, this->layout1));
// Load the layout. In applications layouts are loaded, not added into a container (you don't select a added layout, just load it from this function)
this->LoadLayout(this->layout1);
}
14 changes: 14 additions & 0 deletions Examples/LoopUpdating/Source/MainApplication.main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include <MainApplication.hpp>

// Main entrypoint, call the app here
int main()
{
// Create the application
MainApplication *amain = new MainApplication();
// Show it. This function will finalize when the application's "Close()" function is called.
amain->Show();
// IMPORTANT! free the application to destroy allocated memory and to finalize graphics.
delete amain;
// Exit
return 0;
}
7 changes: 7 additions & 0 deletions Examples/SimpleApplication/Include/MainApplication.hpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@


#pragma once

// Include Plutonium
#include <pu/Plutonium>

// Define your main layout as a class inheriting from pu::Layout
class Layout1 : public pu::Layout
{
public:
Layout1();
private:
// An easy way to keep objects is to have them as private pointer members
pu::element::TextBlock *helloText;
};

// Define your application as a class too
class MainApplication : public pu::Application
{
public:
MainApplication();
private:
// Layout instance
Layout1 *layout1;
};
6 changes: 6 additions & 0 deletions Examples/SimpleApplication/Source/MainApplication.cpp
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
#include <MainApplication.hpp>

// Implement all the layout/application functions here

Layout1::Layout1()
{
// Create the textblock with the text we want
this->helloText = new pu::element::TextBlock(300, 300, "Hello world!");
// Add the textblock to the layout's element container. IMPORTANT! this MUST be done, having them as members is not enough (just a simple way to keep them)
this->AddChild(this->helloText);
}

MainApplication::MainApplication()
{
// Create the layout (calling the constructor above)
this->layout1 = new Layout1();
// Load the layout. In applications layouts are loaded, not added into a container (you don't select a added layout, just load it from this function)
this->LoadLayout(this->layout1);
}
6 changes: 6 additions & 0 deletions Examples/SimpleApplication/Source/MainApplication.main.cpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#include <MainApplication.hpp>

// Main entrypoint, call the app here
int main()
{
// Create the application
MainApplication *amain = new MainApplication();
// Show it. This function will finalize when the application's "Close()" function is called.
amain->Show();
// IMPORTANT! free the application to destroy allocated memory and to finalize graphics.
delete amain;
// Exit
return 0;
}

0 comments on commit 8f51ad6

Please sign in to comment.