Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
StuntHacks committed Sep 27, 2018
2 parents 5890a1c + 8c05422 commit 5285ae2
Show file tree
Hide file tree
Showing 68 changed files with 4,709 additions and 330 deletions.
27 changes: 27 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
language: cpp
dist: trusty
sudo: required
compiler:
- gcc
os:
- linux
before_install:
- wget https://github.com/devkitPro/pacman/releases/download/devkitpro-pacman-1.0.1/devkitpro-pacman.deb
- sudo dpkg -i devkitpro-pacman.deb
- sudo dkp-pacman -S devkitARM picasso tex3ds 3dstools devkit-env libctru citro3d citro2d 3ds-zlib 3ds-tinyxml2 3ds-mpg123 3ds-libpng --noconfirm
script:
- make -C m3dialib/
branches:
only:
- master
- develop
notifications:
email:
recipents:
- stunthacks@gmail.com
on_success: never
on_failure: always
env:
global:
- DEVKITPRO="/opt/devkitpro"
- DEVKITARM="/opt/devkitpro/devkitARM"
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# m3diaLib
# m3diaLib [![Build Status](https://travis-ci.org/StuntHacks/m3diaLib.svg?branch=master)](https://travis-ci.org/StuntHacks/m3diaLib)
A fast, extensive and powerful allround media and game library for the Nintendo 3DS, written in C++.

#### Click [here](#installation) to get to the installation instructions.
Expand Down Expand Up @@ -102,9 +102,9 @@ This module isn't availiable at the moment. However, it's planned features are:
...and anything that strikes my mind in the future.

## Installation
To install the library, download the latest release-build and execute the command `make install`.
To install the library, download the latest build and then execute the command `make install`.

To build it from the source, clone the repository and execute the following commands:
If you want to build it from the source, download the latest release and then execute the following commands:

```
make
Expand All @@ -127,3 +127,5 @@ To compile a m3diaLib-app, you need the following dependencies installed (instal
* [ctrulib](https://github.com/smealum/ctrulib/)
* [citro3d](https://github.com/fincs/citro3d) (zLib)
* [citro2d](https://github.com/devkitPro/citro2d) (zLib)
* [OBJ-Loader](https://github.com/Bly7/OBJ-Loader) (MIT)
* [ctr-led-brary](https://github.com/mariohackandglitch/ctr-led-brary)
51 changes: 45 additions & 6 deletions m3dialib/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#---------------------------------------------------------------------------------
.SUFFIXES:
#---------------------------------------------------------------------------------

ifeq ($(strip $(DEVKITARM)),)
$(error "Please set DEVKITARM in your environment. export DEVKITARM=<path to>devkitARM")
endif
Expand All @@ -23,14 +24,14 @@ VERSION := $(M3D_MAJOR).$(M3D_MINOR).$(M3D_PATCH)
TARGET := $(notdir $(CURDIR))
SOURCES := $(sort $(dir $(wildcard source/*/)))
DATA := data
INCLUDES := $(sort $(dir $(wildcard includes/*/)))
INCLUDES := $(sort $(dir $(wildcard includes/*/)))

#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft

CFLAGS := -g -Wall -Werror -mword-relocations \
CFLAGS := -g -Wall -Werror -mword-relocations -save-temps\
-ffunction-sections -fdata-sections \
$(ARCH) $(BUILD_CFLAGS)

Expand Down Expand Up @@ -59,6 +60,8 @@ export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) \
CFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c)))
CPPFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp)))
SFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.s)))
PICAFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.v.pica)))
SHLISTFILES := $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.shlist)))
BINFILES := $(foreach dir,$(DATA),$(notdir $(wildcard $(dir)/*.*)))

#---------------------------------------------------------------------------------
Expand All @@ -75,14 +78,20 @@ else
endif
#---------------------------------------------------------------------------------

export OFILES := $(addsuffix .o,$(BINFILES)) \
$(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)
export OFILES_SOURCES := $(CPPFILES:.cpp=.o) $(CFILES:.c=.o) $(SFILES:.s=.o)

export OFILES_BIN := $(addsuffix .o,$(BINFILES)) \
$(PICAFILES:.v.pica=.shbin.o) $(SHLISTFILES:.shlist=.shbin.o)

export OFILES := $(OFILES_BIN) $(OFILES_SOURCES)

export HFILES := $(PICAFILES:.v.pica=_shbin.h) $(addsuffix .h,$(subst .,_,$(BINFILES)))

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

.PHONY: clean all doc
.PHONY: clean all docs

#---------------------------------------------------------------------------------
all: lib/libm3dia.a lib/libm3diad.a
Expand Down Expand Up @@ -132,12 +141,42 @@ DEPENDS := $(OFILES:.o=.d)
#---------------------------------------------------------------------------------
$(OUTPUT) : $(OFILES)

$(OFILES_SOURCES) : $(HFILES)

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

#---------------------------------------------------------------------------------
# rules for assembling GPU shaders
#---------------------------------------------------------------------------------
define shader-as
$(eval CURBIN := $*.shbin)
$(eval DEPSFILE := $(DEPSDIR)/$*.shbin.d)
echo "$(CURBIN).o: $< $1" > $(DEPSFILE)
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"_end[];" > `(echo $(CURBIN) | tr . _)`.h
echo "extern const u8" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`"[];" >> `(echo $(CURBIN) | tr . _)`.h
echo "extern const u32" `(echo $(CURBIN) | sed -e 's/^\([0-9]\)/_\1/' | tr . _)`_size";" >> `(echo $(CURBIN) | tr . _)`.h
picasso -o $(CURBIN) $1
bin2s $(CURBIN) | $(AS) -o $*.shbin.o
endef

%.shbin.o %_shbin.h : %.v.pica %.g.pica
@echo $(notdir $^)
@$(call shader-as,$^)

%.shbin.o %_shbin.h : %.v.pica
@echo $(notdir $<)
@$(call shader-as,$<)

%.shbin.o %_shbin.h : %.shlist
@echo $(notdir $<)
@$(call shader-as,$(foreach file,$(shell cat $<),$(dir $<)$(file)))

-include $(DEPENDS)

#---------------------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions m3dialib/includes/m3d/audio/playable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,9 @@ namespace m3d {
virtual void reset() = 0;
};

class Mp3Reader: public m3d::Playable::Reader {
class MP3Reader: public m3d::Playable::Reader {
public:
virtual ~Mp3Reader();
virtual ~MP3Reader();
void set(m3d::Playable::Decoder& t_decoder);
int init(const std::string& t_file);
uint32_t getRate();
Expand All @@ -116,7 +116,7 @@ namespace m3d {
uint8_t m_channels;
};

class WavReader: public m3d::Playable::Reader {
class WAVReader: public m3d::Playable::Reader {
public:
void set(m3d::Playable::Decoder& t_decoder);
int init(const std::string& t_file);
Expand Down
9 changes: 8 additions & 1 deletion m3dialib/includes/m3d/core/applet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ namespace m3d {
* @brief Returns the model of the system
* @return The system model
*/
m3d::Applet::ConsoleModel getConsoleModel();
static m3d::Applet::ConsoleModel getConsoleModel();

/**
* @brief Returns whether the system is connected to a wifi network
Expand Down Expand Up @@ -184,6 +184,13 @@ namespace m3d {
*/
int getCurrentFrame();

/**
* @brief Whether to enable the New 3DS speedup or not
* @param t_enable Whether or not to enable the speedup
* @note By default, the speedup is enabled on New 3DS consoles
*/
static inline void enableSpeedup(bool t_enable);

private:
/* data */
bool m_sleepAllowed, m_running;
Expand Down
1 change: 1 addition & 0 deletions m3dialib/includes/m3d/core/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "applet.hpp"
#include "clock.hpp"
#include "error.hpp"
#include "ledPattern.hpp"
#include "thread.hpp"
#include "time.hpp"

Expand Down
7 changes: 3 additions & 4 deletions m3dialib/includes/m3d/core/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ namespace m3d {
*/
enum class ErrorType {
Text, ///< Displays text passed to this applet
Eula, ///< Displays the EULA
WordWrap ///< Displays the custom error message passed to this applet with automatic line wrapping
WordWrap ///< Displays the custom error message passed to this applet with automatic line wrapping
};

/**
Expand Down Expand Up @@ -74,7 +73,7 @@ namespace m3d {
* @brief Sets whether to allow the use of the home button
* @param t_allowed Whether the use of the home button is allowed or not
*/
void setAllowHomebutton(bool t_allowed);
void allowHomebutton(bool t_allowed);

/**
* @brief Returns whether the use of the home button is allowed
Expand All @@ -86,7 +85,7 @@ namespace m3d {
* @brief Sets whether to show an error code
* @param t_show Whether to show an error code or not
*/
void setShowErrorCode(bool t_show);
void showErrorCode(bool t_show);

/**
* @brief Returns whether to show an error code
Expand Down
115 changes: 115 additions & 0 deletions m3dialib/includes/m3d/core/ledPattern.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* @file ledPattern.hpp
* @brief Defines the LEDPattern class
*/
/*
* Credits for a lot of the internal code to https://github.com/mariohackandglitch/ctr-led-brary
*/
#ifndef LEDPATTERN_H
#define LEDPATTERN_H

#pragma once
#include <3ds.h>
#include <map>
#include <utility>
#include "m3d/graphics/color.hpp"
#include "m3d/private/core.hpp"

namespace m3d {
/**
* @brief The LEDPattern class, used for manipulating the notifications LED
*/
class LEDPattern {
public:
/**
* @brief Constructs the LED pattern
*/
LEDPattern();

/**
* @brief Initializes the LED pattern with a constant color
* @param t_color The color
*/
LEDPattern(m3d::Color t_color);

/**
* @brief Adds a keyframe to the pattern
* @param t_sample The sample-position of the keyframe
* @param t_color The color of the keyframe
* @param t_hold Whether to hold the value of the last keyframe until this one or not
*/
void addKeyFrame(int t_sample, m3d::Color t_color, bool t_hold = false);

/**
* @brief Deletes the keyframe at the given sample-position
* @param t_sample The sample-position
*/
void deleteKeyframe(int t_sample);

/**
* @brief Clears all keyframes
*/
void clearKeyframes();

/**
* @brief Sets the time the pattern should play until it starts again
* @param t_time The time in seconds (ranging from 0.25 to 16.0)
*/
void setTime(float t_time);

/**
* @brief Returns the time the pattern plays until it starts again
* @return The time in seconds
*/
float getTime();

/**
* @brief Sets the time the pattern should wait before it starts again
* @param t_time The time in seconds (ranging from 0 to 16)
* @note When a time >16 is set, the pattern won't loop but will instead keep displaying the last color until it is either stopped or a different pattern is played
*/
void setDelay(float t_delay);

/**
* @brief Returns the time the pattern waits before it starts again
* @return The time in seconds
*/
float getDelay();

/**
* @brief Plays the pattern
*/
void play();

/**
* @brief Returns whether a pattern is currently playing or not
* @return `true` if there is an LED pattern playing, `false` otherwise
*/
static bool isPlaying();

/**
* @brief Stops any LED pattern that's currently active
*/
static void stop();

private:
struct Pattern
{
u8 delay;
u8 smooth;
u8 loop_delay;
u8 unknown1;
u8 r[32];
u8 g[32];
u8 b[32];
};

/* data */
std::map<int, std::pair<m3d::Color, bool>> m_keyFrames;
float m_time, m_delay;

};
} /* m3d */


#endif /* end of include guard: LEDPATTERN_H */
7 changes: 7 additions & 0 deletions m3dialib/includes/m3d/core/mutex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ namespace m3d {
*/
Mutex();

/**
* @brief Destructor
*
* This automatically unlocks the mutex
*/
~Mutex();

/**
* @brief Locks the mutex
*/
Expand Down
7 changes: 6 additions & 1 deletion m3dialib/includes/m3d/core/thread.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#pragma once
#include <3ds.h>
#include <atomic>
#include <functional>
#include <string>
#include "parameter.hpp"
Expand Down Expand Up @@ -74,6 +75,8 @@ namespace m3d {
*/
void join(long long unsigned int t_timeout = U64_MAX);

bool isRunning();

/**
* @brief Puts the thread to sleep
*
Expand All @@ -91,12 +94,14 @@ namespace m3d {
struct ThreadData {
m3d::Parameter m_parameter;
std::function<void(m3d::Parameter)> m_function;
std::atomic<bool>* m_running;
};

static void threadFunction(void* t_arg);
/* data */
int m_priority, m_stackSize;
bool m_running, m_started;
bool m_started;
std::atomic<bool> m_running;
m3d::Thread::ThreadData m_data;
CTRU_Thread m_thread;
};
Expand Down
Loading

0 comments on commit 5285ae2

Please sign in to comment.