more schizophrenic fixes for the dreamcast build (for audio/graphics to still be broken), dropped freetype for stb_truetype (to shrink the DC binary down to 2.6MB)
This commit is contained in:
parent
c61e502dcb
commit
9ac47e843f
1
.gitignore
vendored
1
.gitignore
vendored
@ -69,4 +69,5 @@ models/
|
||||
llm/
|
||||
tmp/
|
||||
|
||||
*.map
|
||||
engine/lib/dreamcast/gcc/opengl/
|
||||
@ -59,6 +59,8 @@ destination(children.circleIn, nil, 2, 0)
|
||||
destination(children.start, -1.5, nil, 0)
|
||||
destination(children.quit, -1.5, nil, 0)
|
||||
|
||||
-- ?
|
||||
--[[
|
||||
ent:addHook("asset:Load.%UID%", function( json )
|
||||
local filename = json["filename"]
|
||||
if filename == "" or string.extension( filename ) ~= "ogg" then return false end
|
||||
@ -71,6 +73,7 @@ ent:addHook("asset:Load.%UID%", function( json )
|
||||
|
||||
return true
|
||||
end )
|
||||
]]
|
||||
|
||||
local selectableElements = {
|
||||
children.start,
|
||||
@ -245,4 +248,4 @@ updateVisuals(ent, 0)
|
||||
ent:bind( "tick", function(self)
|
||||
handleSelectionIndex()
|
||||
updateVisuals(self, time.delta())
|
||||
end )
|
||||
end )
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
},
|
||||
"bgm": {
|
||||
"tracks": {
|
||||
"/ui/tmrwah.ogg": {}
|
||||
"/ui/bgm.wav": {}
|
||||
// "/ui/main menu.ogg": {}
|
||||
// "/ui/tainted.ogg": {
|
||||
// "intro": "/ui/tainted_intro.ogg",
|
||||
|
||||
@ -94,7 +94,7 @@
|
||||
"flatten transforms": false
|
||||
},
|
||||
"audio": {
|
||||
"mute": true,
|
||||
"mute": false,
|
||||
"async update": false,
|
||||
"streams by default": true,
|
||||
"buffers": {
|
||||
@ -108,7 +108,7 @@
|
||||
}
|
||||
},
|
||||
"memory pool": {
|
||||
"enabled": true, // probably should be enabled
|
||||
"enabled": false, // probably should be enabled
|
||||
"subPools": false,
|
||||
"alignment": 4,
|
||||
"override": false,
|
||||
|
||||
5079
dep/include/stb/stb_truetype.h
Normal file
5079
dep/include/stb/stb_truetype.h
Normal file
File diff suppressed because it is too large
Load Diff
27
engine/inc/uf/ext/aica/aica.h
Normal file
27
engine/inc/uf/ext/aica/aica.h
Normal file
@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#if UF_ENV_DREAMCAST && UF_USE_AICA
|
||||
#include <uf/config.h>
|
||||
|
||||
#include <uf/utils/memory/string.h>
|
||||
#include <uf/utils/memory/vector.h>
|
||||
|
||||
#include "al.h"
|
||||
#include "source.h"
|
||||
#include "buffer.h"
|
||||
#include "filter.h"
|
||||
#include "listener.h"
|
||||
|
||||
#include <uf/utils/audio/metadata.h>
|
||||
#include <uf/utils/math/transform.h>
|
||||
|
||||
namespace ext {
|
||||
namespace al {
|
||||
void UF_API initialize();
|
||||
void UF_API destroy();
|
||||
|
||||
uf::stl::string UF_API getError( ALenum = 0 );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
140
engine/inc/uf/ext/aica/al.h
Normal file
140
engine/inc/uf/ext/aica/al.h
Normal file
@ -0,0 +1,140 @@
|
||||
#pragma once
|
||||
|
||||
typedef char ALboolean;
|
||||
typedef char ALchar;
|
||||
typedef signed char ALbyte;
|
||||
typedef unsigned char ALubyte;
|
||||
typedef short ALshort;
|
||||
typedef unsigned short ALushort;
|
||||
typedef int ALint;
|
||||
typedef unsigned int ALuint;
|
||||
typedef int ALsizei;
|
||||
typedef int ALenum;
|
||||
typedef float ALfloat;
|
||||
typedef double ALdouble;
|
||||
typedef void ALvoid;
|
||||
|
||||
#define AL_NONE 0
|
||||
#define AL_FALSE 0
|
||||
#define AL_TRUE 1
|
||||
#define AL_SOURCE_RELATIVE 0x202
|
||||
#define AL_CONE_INNER_ANGLE 0x1001
|
||||
#define AL_CONE_OUTER_ANGLE 0x1002
|
||||
#define AL_PITCH 0x1003
|
||||
#define AL_POSITION 0x1004
|
||||
#define AL_DIRECTION 0x1005
|
||||
#define AL_VELOCITY 0x1006
|
||||
#define AL_LOOPING 0x1007
|
||||
#define AL_BUFFER 0x1009
|
||||
#define AL_GAIN 0x100A
|
||||
#define AL_MIN_GAIN 0x100D
|
||||
#define AL_MAX_GAIN 0x100E
|
||||
#define AL_ORIENTATION 0x100F
|
||||
#define AL_SOURCE_STATE 0x1010
|
||||
#define AL_INITIAL 0x1011
|
||||
#define AL_PLAYING 0x1012
|
||||
#define AL_PAUSED 0x1013
|
||||
#define AL_STOPPED 0x1014
|
||||
#define AL_BUFFERS_QUEUED 0x1015
|
||||
#define AL_BUFFERS_PROCESSED 0x1016
|
||||
#define AL_REFERENCE_DISTANCE 0x1020
|
||||
#define AL_ROLLOFF_FACTOR 0x1021
|
||||
#define AL_CONE_OUTER_GAIN 0x1022
|
||||
#define AL_MAX_DISTANCE 0x1023
|
||||
#define AL_SEC_OFFSET 0x1024
|
||||
#define AL_SAMPLE_OFFSET 0x1025
|
||||
#define AL_BYTE_OFFSET 0x1026
|
||||
#define AL_SOURCE_TYPE 0x1027
|
||||
#define AL_STATIC 0x1028
|
||||
#define AL_STREAMING 0x1029
|
||||
#define AL_UNDETERMINED 0x1030
|
||||
#define AL_FORMAT_MONO8 0x1100
|
||||
#define AL_FORMAT_MONO16 0x1101
|
||||
#define AL_FORMAT_STEREO8 0x1102
|
||||
#define AL_FORMAT_STEREO16 0x1103
|
||||
#define AL_FREQUENCY 0x2001
|
||||
#define AL_BITS 0x2002
|
||||
#define AL_CHANNELS 0x2003
|
||||
#define AL_SIZE 0x2004
|
||||
#define AL_UNUSED 0x2010
|
||||
#define AL_PENDING 0x2011
|
||||
#define AL_PROCESSED 0x2012
|
||||
#define AL_NO_ERROR 0
|
||||
#define AL_INVALID_NAME 0xA001
|
||||
#define AL_INVALID_ENUM 0xA002
|
||||
#define AL_INVALID_VALUE 0xA003
|
||||
#define AL_INVALID_OPERATION 0xA004
|
||||
#define AL_OUT_OF_MEMORY 0xA005
|
||||
#define AL_VENDOR 0xB001
|
||||
#define AL_VERSION 0xB002
|
||||
#define AL_RENDERER 0xB003
|
||||
#define AL_EXTENSIONS 0xB004
|
||||
#define AL_DOPPLER_FACTOR 0xC000
|
||||
#define AL_DOPPLER_VELOCITY 0xC001
|
||||
#define AL_SPEED_OF_SOUND 0xC003
|
||||
#define AL_DISTANCE_MODEL 0xD000
|
||||
#define AL_INVERSE_DISTANCE 0xD001
|
||||
#define AL_INVERSE_DISTANCE_CLAMPED 0xD002
|
||||
#define AL_LINEAR_DISTANCE 0xD003
|
||||
#define AL_LINEAR_DISTANCE_CLAMPED 0xD004
|
||||
#define AL_EXPONENT_DISTANCE 0xD005
|
||||
#define AL_EXPONENT_DISTANCE_CLAMPED 0xD006
|
||||
|
||||
#define AL_EFFECTSLOT_NULL 0x0000
|
||||
#define AL_EFFECTSLOT_EFFECT 0x0001
|
||||
#define AL_EFFECTSLOT_GAIN 0x0002
|
||||
#define AL_EFFECTSLOT_AUXILIARY_SEND_AUTO 0x0003
|
||||
#define AL_FILTER_TYPE 0x8001
|
||||
#define AL_FILTER_NULL 0x0000
|
||||
#define AL_FILTER_LOWPASS 0x0001
|
||||
#define AL_FILTER_HIGHPASS 0x0002
|
||||
#define AL_FILTER_BANDPASS 0x0003
|
||||
#define AL_EFFECT_TYPE 0x8001
|
||||
#define AL_EFFECT_NULL 0x0000
|
||||
#define AL_EFFECT_EAXREVERB 0x8000
|
||||
#define AL_EFFECT_REVERB 0x0001
|
||||
#define AL_EFFECT_CHORUS 0x0002
|
||||
#define AL_EFFECT_DISTORTION 0x0003
|
||||
#define AL_EFFECT_ECHO 0x0004
|
||||
#define AL_EFFECT_FLANGER 0x0005
|
||||
#define AL_EFFECT_FREQUENCY_SHIFTER 0x0006
|
||||
#define AL_EFFECT_VOCAL_MORPHER 0x0007
|
||||
#define AL_EFFECT_PITCH_SHIFTER 0x0008
|
||||
#define AL_EFFECT_RING_MODULATOR 0x0009
|
||||
#define AL_EFFECT_AUTOWAH 0x000A
|
||||
#define AL_EFFECT_COMPRESSOR 0x000B
|
||||
#define AL_EFFECT_EQUALIZER 0x000C
|
||||
#define AL_REVERB_DENSITY 0x0001
|
||||
#define AL_REVERB_DIFFUSION 0x0002
|
||||
#define AL_REVERB_GAIN 0x0003
|
||||
#define AL_REVERB_GAINHF 0x0004
|
||||
#define AL_REVERB_DECAY_TIME 0x0005
|
||||
#define AL_REVERB_DECAY_HFRATIO 0x0006
|
||||
#define AL_REVERB_REFLECTIONS_GAIN 0x0007
|
||||
#define AL_REVERB_REFLECTIONS_DELAY 0x0008
|
||||
#define AL_REVERB_LATE_REVERB_GAIN 0x0009
|
||||
#define AL_REVERB_LATE_REVERB_DELAY 0x000A
|
||||
#define AL_REVERB_AIR_ABSORPTION_GAINHF 0x000B
|
||||
#define AL_REVERB_ROOM_ROLLOFF_FACTOR 0x000C
|
||||
#define AL_REVERB_DECAY_HFLIMIT 0x000D
|
||||
#define AL_ECHO_DELAY 0x0001
|
||||
#define AL_ECHO_LRDELAY 0x0002
|
||||
#define AL_ECHO_DAMPING 0x0003
|
||||
#define AL_ECHO_FEEDBACK 0x0004
|
||||
#define AL_ECHO_SPREAD 0x0005
|
||||
#define AL_METERS_PER_UNIT 0x20004
|
||||
#define AL_DIRECT_FILTER 0x20005
|
||||
#define AL_AUXILIARY_SEND_FILTER 0x20006
|
||||
#define AL_AIR_ABSORPTION_FACTOR 0x20007
|
||||
#define AL_ROOM_ROLLOFF_FACTOR 0x20008
|
||||
#define AL_CONE_OUTER_GAINHF 0x20009
|
||||
#define AL_DIRECT_FILTER_GAINHF_AUTO 0x2000A
|
||||
#define AL_AUXILIARY_SEND_FILTER_GAIN_AUTO 0x2000B
|
||||
#define AL_AUXILIARY_SEND_FILTER_GAINHF_AUTO 0x2000C
|
||||
#define ALC_EFX_MAJOR_VERSION 0x20001
|
||||
#define ALC_EFX_MINOR_VERSION 0x20002
|
||||
#define ALC_MAX_AUXILIARY_SENDS 0x20003
|
||||
|
||||
#define AL_STREAM_HANDLE 0x10001
|
||||
#define AL_STREAM_FILL_CALLBACK 0x10002
|
||||
#define AL_STREAM_USER_DATA 0x10003
|
||||
32
engine/inc/uf/ext/aica/buffer.h
Normal file
32
engine/inc/uf/ext/aica/buffer.h
Normal file
@ -0,0 +1,32 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
#if UF_ENV_DREAMCAST
|
||||
|
||||
#include "al.h"
|
||||
|
||||
namespace ext {
|
||||
namespace al {
|
||||
class UF_API Buffer {
|
||||
protected:
|
||||
uf::stl::vector<ALuint> m_indices;
|
||||
public:
|
||||
bool initialized() const;
|
||||
|
||||
ALuint& getIndex( size_t = 0 );
|
||||
ALuint getIndex( size_t = 0 ) const;
|
||||
|
||||
void buffer( ALenum, const ALvoid*, ALsizei, ALsizei, size_t = 0 );
|
||||
static void buffer( ALuint index, ALenum, const ALvoid*, ALsizei, ALsizei );
|
||||
|
||||
void set( ALenum, ALint*, size_t = 0 );
|
||||
void set( ALenum name, ALint value, size_t i = 0 );
|
||||
void get( ALenum name, ALint& value, size_t i = 0 ) const;
|
||||
void poll( size_t = 0 );
|
||||
|
||||
void initialize( size_t = 1 );
|
||||
void destroy();
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
43
engine/inc/uf/ext/aica/filter.h
Normal file
43
engine/inc/uf/ext/aica/filter.h
Normal file
@ -0,0 +1,43 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
#if UF_ENV_DREAMCAST
|
||||
|
||||
#include "al.h"
|
||||
|
||||
namespace ext {
|
||||
namespace al {
|
||||
class Filter {
|
||||
protected:
|
||||
ALuint m_index = 0;
|
||||
public:
|
||||
void initialize();
|
||||
void destroy();
|
||||
ALuint getIndex() const;
|
||||
void set( ALenum name, ALfloat x );
|
||||
void set( ALenum name, ALint x );
|
||||
};
|
||||
class Effect {
|
||||
ALuint m_index = 0;
|
||||
public:
|
||||
void initialize();
|
||||
void destroy();
|
||||
ALuint getIndex() const;
|
||||
|
||||
void set( ALenum name, ALfloat x );
|
||||
void set( ALenum name, ALint x );
|
||||
};
|
||||
|
||||
class EffectSlot {
|
||||
ALuint m_index = 0;
|
||||
public:
|
||||
void initialize();
|
||||
void destroy();
|
||||
ALuint getIndex() const;
|
||||
|
||||
void set( ALenum name, ALfloat x );
|
||||
void set( ALenum name, ALint x );
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
20
engine/inc/uf/ext/aica/listener.h
Normal file
20
engine/inc/uf/ext/aica/listener.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
#if UF_ENV_DREAMCAST
|
||||
|
||||
#include "al.h"
|
||||
#include <uf/utils/math/vector.h>
|
||||
|
||||
namespace ext {
|
||||
namespace al {
|
||||
class UF_API Listener {
|
||||
public:
|
||||
static void set( ALenum name, ALfloat x, ALfloat y, ALfloat z );
|
||||
static void set( ALenum name, const ALfloat* values );
|
||||
static pod::Vector3f getPosition();
|
||||
static pod::Vector3f getRight();
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
62
engine/inc/uf/ext/aica/source.h
Normal file
62
engine/inc/uf/ext/aica/source.h
Normal file
@ -0,0 +1,62 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
#if UF_ENV_DREAMCAST
|
||||
|
||||
#include "al.h"
|
||||
|
||||
namespace ext {
|
||||
namespace al {
|
||||
class UF_API Source {
|
||||
protected:
|
||||
ALuint m_index = 0;
|
||||
public:
|
||||
void initialize();
|
||||
void destroy();
|
||||
|
||||
ALuint& getIndex();
|
||||
ALuint getIndex() const;
|
||||
|
||||
void get( ALenum name, ALfloat& x ) const;
|
||||
void get( ALenum name, ALfloat& x, ALfloat& y, ALfloat& z ) const;
|
||||
void get( ALenum name, ALfloat* f ) const;
|
||||
|
||||
void get( ALenum name, ALint& x ) const;
|
||||
void get( ALenum name, ALint& x, ALint& y, ALint& z ) const;
|
||||
void get( ALenum name, ALint* f ) const;
|
||||
|
||||
void set( ALenum name, ALfloat x );
|
||||
void set( ALenum name, ALfloat x, ALfloat y, ALfloat z );
|
||||
void set( ALenum name, const ALfloat* f );
|
||||
|
||||
void set( ALenum name, ALint x );
|
||||
void set( ALenum name, ALint x, ALint y, ALint z );
|
||||
void set( ALenum name, const ALint* f );
|
||||
|
||||
void get( const uf::stl::string& name, ALfloat& x ) const;
|
||||
void get( const uf::stl::string& name, ALfloat& x, ALfloat& y, ALfloat& z ) const;
|
||||
void get( const uf::stl::string& name, ALfloat* f ) const;
|
||||
|
||||
void get( const uf::stl::string& name, ALint& x ) const;
|
||||
void get( const uf::stl::string& name, ALint& x, ALint& y, ALint& z ) const;
|
||||
void get( const uf::stl::string& name, ALint* f ) const;
|
||||
|
||||
void set( const uf::stl::string& name, ALfloat x );
|
||||
void set( const uf::stl::string& name, ALfloat x, ALfloat y, ALfloat z );
|
||||
void set( const uf::stl::string& name, const ALfloat* f );
|
||||
|
||||
void set( const uf::stl::string& name, ALint x );
|
||||
void set( const uf::stl::string& name, ALint x, ALint y, ALint z );
|
||||
void set( const uf::stl::string& name, const ALint* f );
|
||||
|
||||
void queue( ALsizei n, ALuint* buffers );
|
||||
void unqueue( ALsizei n, ALuint* buffers );
|
||||
|
||||
void play();
|
||||
void pause();
|
||||
void stop();
|
||||
bool playing() const;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -15,6 +15,10 @@
|
||||
#include <uf/ext/toml/toml.h>
|
||||
#endif
|
||||
|
||||
#if UF_ENV_DREAMCAST
|
||||
#define JSON_NO_IO
|
||||
#endif
|
||||
|
||||
namespace ext {
|
||||
namespace json {
|
||||
extern uf::stl::string PREFERRED_COMPRESSION;
|
||||
|
||||
@ -18,10 +18,10 @@
|
||||
#define float64_t decltype(1.0L)
|
||||
|
||||
namespace std {
|
||||
using ::snprintf;
|
||||
using ::strtoull;
|
||||
using ::strtoll;
|
||||
using ::strtold;
|
||||
using ::snprintf;
|
||||
using ::strtoull;
|
||||
using ::strtoll;
|
||||
using ::strtold;
|
||||
}
|
||||
#else
|
||||
#define float64_t double
|
||||
|
||||
@ -21,7 +21,12 @@ namespace ext {
|
||||
ALuint& getIndex( size_t = 0 );
|
||||
ALuint getIndex( size_t = 0 ) const;
|
||||
|
||||
void buffer(ALenum, const ALvoid*, ALsizei, ALsizei, size_t = 0);
|
||||
void buffer( ALenum, const ALvoid*, ALsizei, ALsizei, size_t = 0 );
|
||||
static void buffer( ALuint index, ALenum, const ALvoid*, ALsizei, ALsizei );
|
||||
|
||||
void set( ALenum, ALint*, size_t = 0 );
|
||||
void set( ALenum name, ALint value, size_t i = 0 );
|
||||
void get( ALenum name, ALint& value, size_t i = 0 ) const;
|
||||
|
||||
void initialize( size_t = 1 );
|
||||
void destroy();
|
||||
|
||||
20
engine/inc/uf/ext/openal/listener.h
Normal file
20
engine/inc/uf/ext/openal/listener.h
Normal file
@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
#if UF_USE_OPENAL
|
||||
|
||||
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
#include <AL/alut.h>
|
||||
|
||||
namespace ext {
|
||||
namespace al {
|
||||
class UF_API Listener {
|
||||
public:
|
||||
static void set( ALenum name, ALfloat x, ALfloat y, ALfloat z );
|
||||
static void set( ALenum name, const ALfloat* values );
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
#if UF_USE_OPENAL
|
||||
#if UF_USE_OPENAL && !UF_USE_AICA
|
||||
|
||||
#include <AL/al.h>
|
||||
#include <AL/alc.h>
|
||||
@ -28,6 +28,7 @@
|
||||
#include "source.h"
|
||||
#include "buffer.h"
|
||||
#include "filter.h"
|
||||
#include "listener.h"
|
||||
#include <uf/utils/audio/metadata.h>
|
||||
#include <uf/utils/math/transform.h>
|
||||
|
||||
|
||||
@ -55,7 +55,11 @@ namespace ext {
|
||||
void set( const uf::stl::string& name, ALint x, ALint y, ALint z );
|
||||
void set( const uf::stl::string& name, const ALint* f );
|
||||
|
||||
void queue( ALsizei n, ALuint* buffers );
|
||||
void unqueue( ALsizei n, ALuint* buffers );
|
||||
|
||||
void play();
|
||||
void pause();
|
||||
void stop();
|
||||
bool playing() const;
|
||||
};
|
||||
|
||||
36
engine/inc/uf/ext/truetype/truetype.h
Normal file
36
engine/inc/uf/ext/truetype/truetype.h
Normal file
@ -0,0 +1,36 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
#if UF_USE_TRUETYPE
|
||||
|
||||
#include <uf/utils/string/string.h>
|
||||
#include <uf/utils/memory/vector.h>
|
||||
#include <memory>
|
||||
|
||||
namespace pod {
|
||||
struct TrueTypeFont {
|
||||
void* info;
|
||||
float scale = 1.0f;
|
||||
uint64_t current_codepoint = 0;
|
||||
|
||||
TrueTypeFont();
|
||||
~TrueTypeFont();
|
||||
};
|
||||
}
|
||||
|
||||
namespace ext {
|
||||
namespace truetype {
|
||||
bool UF_API initialize();
|
||||
void UF_API terminate();
|
||||
|
||||
bool UF_API initialize( pod::TrueTypeFont&, const uf::stl::string& );
|
||||
void UF_API destroy( pod::TrueTypeFont& );
|
||||
|
||||
void UF_API setPixelSizes( pod::TrueTypeFont&, size_t );
|
||||
|
||||
bool UF_API load( pod::TrueTypeFont&, uint64_t );
|
||||
bool UF_API load( pod::TrueTypeFont&, const uf::stl::string& );
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -11,6 +11,22 @@
|
||||
#define FORCE_INLINE __attribute__((always_inline)) inline
|
||||
// #define FORCE_INLINE inline
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define NO_INLINE __attribute__((noinline))
|
||||
#elif defined(_MSC_VER)
|
||||
#define NO_INLINE __declspec(noinline)
|
||||
#else
|
||||
#define NO_INLINE
|
||||
#endif
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define NO_LTO_ICE __attribute__((noinline, noclone))
|
||||
#elif defined(_MSC_VER)
|
||||
#define NO_LTO_ICE __declspec(noinline)
|
||||
#else
|
||||
#define NO_LTO_ICE
|
||||
#endif
|
||||
|
||||
#define TIMER(x, ...)\
|
||||
static bool first = true;\
|
||||
static uf::Timer<long long> timer(false);\
|
||||
@ -37,6 +53,8 @@
|
||||
#define UF_MSG_WARNING(...) UF_MSG("WARNING", __VA_ARGS__);
|
||||
#define UF_MSG_ERROR(...) UF_MSG("ERROR", __VA_ARGS__);
|
||||
|
||||
#define UF_MSG_ECHO(f) { UF_MSG_DEBUG("{}", #f); f; }
|
||||
|
||||
#if UF_NO_EXCEPTIONS
|
||||
#define UF_EXCEPTIONS 0
|
||||
#define UF_EXCEPTION(...) {\
|
||||
|
||||
@ -4,6 +4,8 @@
|
||||
|
||||
#if UF_USE_OPENAL
|
||||
#include <uf/ext/openal/openal.h>
|
||||
#elif UF_ENV_DREAMCAST
|
||||
#include <uf/ext/aica/aica.h>
|
||||
#else
|
||||
namespace ext {
|
||||
namespace al {
|
||||
@ -43,7 +45,7 @@ namespace uf {
|
||||
|
||||
void UF_API initialize( pod::AudioClip& clip, uint8_t buffers = uf::audio::buffers );
|
||||
void UF_API initialize( pod::AudioSource& source );
|
||||
bool UF_API load( pod::AudioClip& clip, const uf::stl::string& filename, bool streamed = uf::audio::streamsByDefault );
|
||||
bool UF_API load( pod::AudioClip& clip, const uf::stl::string& filename );
|
||||
void UF_API destroy( pod::AudioClip& clip );
|
||||
void UF_API bind( pod::AudioSource& source, pod::AudioClip* clip );
|
||||
void UF_API play( pod::AudioSource& source );
|
||||
|
||||
@ -10,25 +10,38 @@
|
||||
namespace pod {
|
||||
struct Range;
|
||||
|
||||
struct File {
|
||||
void* handle = nullptr;
|
||||
|
||||
size_t (*read)(void* handle, void* buffer, size_t bytes) = nullptr;
|
||||
bool (*seek)(void* handle, long offset, int origin) = nullptr;
|
||||
size_t (*tell)(void* handle) = nullptr;
|
||||
void (*close)(void* handle) = nullptr;
|
||||
|
||||
operator bool() const { return handle != nullptr; }
|
||||
};
|
||||
|
||||
struct Mount {
|
||||
uf::stl::string prefix = "";
|
||||
uf::stl::string path = "";
|
||||
int priority = 0;
|
||||
pod::PointeredUserdata userdata;
|
||||
|
||||
std::function<bool(pod::Mount&, const uf::stl::string&)> exists;
|
||||
std::function<size_t(pod::Mount&, const uf::stl::string&)> size;
|
||||
std::function<size_t(pod::Mount&, const uf::stl::string&)> mtime;
|
||||
std::function<bool(pod::Mount&, const uf::stl::string&, uf::stl::vector<uint8_t>&)> read;
|
||||
std::function<size_t(pod::Mount&, const uf::stl::string&, const void*, size_t)> write;
|
||||
std::function<bool(pod::Mount&, const uf::stl::string&)> mkdir;
|
||||
std::function<uf::stl::vector<uf::stl::string>(pod::Mount&, const uf::stl::string&, const uf::stl::string&, bool)> list;
|
||||
bool (*exists) (pod::Mount&, const uf::stl::string&) = nullptr;
|
||||
size_t (*size) (pod::Mount&, const uf::stl::string&) = nullptr;
|
||||
size_t (*mtime) (pod::Mount&, const uf::stl::string&) = nullptr;
|
||||
bool (*read) (pod::Mount&, const uf::stl::string&, uf::stl::vector<uint8_t>&) = nullptr;
|
||||
size_t (*write) (pod::Mount&, const uf::stl::string&, const void*, size_t) = nullptr;
|
||||
bool (*mkdir) (pod::Mount&, const uf::stl::string&) = nullptr;
|
||||
bool (*stream) (pod::Mount&, const uf::stl::string&, size_t, std::function<bool(const uint8_t* data, size_t size)>) = nullptr;
|
||||
pod::File (*open) (pod::Mount&, const uf::stl::string&) = nullptr;
|
||||
|
||||
std::function<bool(pod::Mount&, const uf::stl::string&, size_t, size_t, uf::stl::vector<uint8_t>&)> readRange;
|
||||
std::function<bool(pod::Mount&, const uf::stl::string&, const uf::stl::vector<pod::Range>&, uf::stl::vector<uint8_t>&)> readRanges;
|
||||
|
||||
std::function<bool(pod::Mount&, const uf::stl::string&, size_t, std::function<bool(const uint8_t* data, size_t size)>)> stream;
|
||||
uf::stl::vector<uf::stl::string> (*list)(pod::Mount&, const uf::stl::string&, const uf::stl::string&, bool) = nullptr;
|
||||
|
||||
bool (*readRange) (pod::Mount&, const uf::stl::string&, size_t, size_t, uf::stl::vector<uint8_t>&) = nullptr;
|
||||
bool (*readRanges)(pod::Mount&, const uf::stl::string&, const uf::stl::vector<pod::Range>&, uf::stl::vector<uint8_t>&) = nullptr;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
namespace uf {
|
||||
@ -55,12 +68,12 @@ namespace uf {
|
||||
size_t UF_API write( const uf::stl::string& path, uf::stl::vector<uint8_t>& buffer );
|
||||
bool UF_API mkdir( const uf::stl::string& path );
|
||||
uf::stl::vector<uf::stl::string> UF_API list( const uf::stl::string& path, const uf::stl::string& extension = "", bool recursive = false );
|
||||
bool UF_API stream( const uf::stl::string& path, size_t chunkSize, std::function<bool(const uint8_t* data, size_t size)> callback );
|
||||
pod::File UF_API open( const uf::stl::string& path );
|
||||
|
||||
bool UF_API readRange( const uf::stl::string& path, size_t start, size_t len, uf::stl::vector<uint8_t>& buffer );
|
||||
bool UF_API readRanges( const uf::stl::string& path, const uf::stl::vector<pod::Range>& ranges, uf::stl::vector<uint8_t>& buffer );
|
||||
|
||||
bool UF_API stream( const uf::stl::string& path, size_t chunkSize, std::function<bool(const uint8_t* data, size_t size)> callback );
|
||||
|
||||
pod::Mount UF_API createDiskMount( const uf::stl::string& uri, int priority = 0 );
|
||||
uf::stl::string UF_API resolveBase( const uf::stl::string& path );
|
||||
}
|
||||
|
||||
@ -308,10 +308,13 @@ template<typename T> pod::Vector4t<T> uf::matrix::multiply( const pod::Matrix4t<
|
||||
#endif
|
||||
#if UF_ENV_DREAMCAST
|
||||
MATH_Load_XMTRX( (ALL_FLOATS_STRUCT*) &mat[0] );
|
||||
auto t = MATH_Matrix_Transform( v[0], v[1], v[2], v[3] );
|
||||
auto res = *((pod::Vector4t<T>*) &t);
|
||||
if ( div && res.w > 0 ) res /= res.w;
|
||||
return res;
|
||||
union {
|
||||
RETURN_VECTOR_STRUCT i;
|
||||
pod::Vector4t<T> o;
|
||||
} u;
|
||||
u.i = MATH_Matrix_Transform( v[0], v[1], v[2], v[3] );
|
||||
if ( div && v.w > 0 ) u.o /= u.o.w;
|
||||
return u.o;
|
||||
#else
|
||||
auto res = pod::Vector4t<T>{
|
||||
v[0] * mat(0,0) + v[1] * mat(0,1) + v[2] * mat(0,2) + v[3] * mat(0,3),
|
||||
|
||||
@ -861,8 +861,12 @@ T uf::vector::cross( const T& a, const T& b ) {
|
||||
}
|
||||
#elif UF_ENV_DREAMCAST && UF_ENV_DREAMCAST_SIMD
|
||||
if constexpr ( simd_able_v<typename T::type_t> ) {
|
||||
auto res = MATH_Cross_Product( a.x, a.y, a.z, b.x, b.y, b.z );
|
||||
return *((T*) &res);
|
||||
union {
|
||||
RETURN_VECTOR_STRUCT i;
|
||||
T o;
|
||||
} u;
|
||||
u.i = MATH_Cross_Product( a.x, a.y, a.z, b.x, b.y, b.z );
|
||||
return u.o;
|
||||
}
|
||||
#endif
|
||||
T res{
|
||||
|
||||
@ -6,18 +6,24 @@
|
||||
#include <type_traits>
|
||||
|
||||
#define UF_MEMORYPOOL_USE_ALLOCATOR 1
|
||||
#if UF_ENV_DREAMCAST
|
||||
#define UF_MEMORYPOOL_OVERRIDE_DEFAULT 0
|
||||
#else
|
||||
#define UF_MEMORYPOOL_OVERRIDE_DEFAULT 1
|
||||
#endif
|
||||
|
||||
|
||||
#if __clang__
|
||||
#define UF_MEMORYPOOL_OVERRIDE_NEW_DELETE 0
|
||||
#else
|
||||
#define UF_MEMORYPOOL_OVERRIDE_NEW_DELETE 1
|
||||
#define UF_MEMORYPOOL_OVERRIDE_NEW_DELETE 0
|
||||
#endif
|
||||
|
||||
namespace uf {
|
||||
namespace allocator {
|
||||
extern UF_API bool override;
|
||||
void UF_API override( bool state );
|
||||
|
||||
void* UF_API allocate( size_t n);
|
||||
void* UF_API allocate( size_t n );
|
||||
void UF_API deallocate( void* p, size_t n = 0 );
|
||||
|
||||
void* UF_API malloc_m( size_t n );
|
||||
|
||||
@ -1,12 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <uf/config.h>
|
||||
#if UF_USE_FREETYPE
|
||||
#if UF_USE_TRUETYPE
|
||||
#include <uf/utils/memory/vector.h>
|
||||
|
||||
#include <uf/utils/math/vector.h>
|
||||
#include <uf/ext/freetype/freetype.h>
|
||||
#include <uf/utils/memory/vector.h>
|
||||
#include <uf/ext/truetype/truetype.h>
|
||||
#include <uf/utils/image/atlas.h>
|
||||
#include <uf/utils/mesh/mesh.h>
|
||||
|
||||
@ -16,7 +14,7 @@ namespace pod {
|
||||
pod::Vector2i bearing = {};
|
||||
pod::Vector2i advance = {};
|
||||
pod::Vector2i padding = {};
|
||||
size_t spread = 0; // 0 if not-SDF
|
||||
size_t spread = 0;
|
||||
|
||||
uf::stl::vector<uint8_t> buffer;
|
||||
};
|
||||
@ -24,10 +22,10 @@ namespace pod {
|
||||
|
||||
namespace uf {
|
||||
namespace glyph {
|
||||
pod::FT_Glyph UF_API initialize( const uf::stl::string& font );
|
||||
uint8_t* UF_API generate( pod::Glyph& glyph, pod::FT_Glyph& face, uint64_t c, size_t size = 48 );
|
||||
uint8_t* UF_API generate( pod::Glyph& glyph, pod::FT_Glyph& face, const uf::stl::string& s, size_t size = 48 );
|
||||
uint8_t* UF_API generate( pod::Glyph& glyph, pod::FT_Glyph& face );
|
||||
pod::TrueTypeFont UF_API initialize( const uf::stl::string& font );
|
||||
uint8_t* UF_API generate( pod::Glyph& glyph, pod::TrueTypeFont& face, uint64_t c, size_t size = 48 );
|
||||
uint8_t* UF_API generate( pod::Glyph& glyph, pod::TrueTypeFont& face, const uf::stl::string& s, size_t size = 48 );
|
||||
uint8_t* UF_API generate( pod::Glyph& glyph, pod::TrueTypeFont& face );
|
||||
|
||||
void UF_API generateSdf( pod::Glyph& glyph );
|
||||
}
|
||||
|
||||
@ -16,6 +16,7 @@
|
||||
#include <uf/engine/graph/graph.h>
|
||||
#include <uf/engine/scene/scene.h>
|
||||
#include <uf/ext/zlib/zlib.h>
|
||||
#include <uf/ext/texconv/texconv.h>
|
||||
|
||||
#include <mutex>
|
||||
|
||||
@ -317,7 +318,7 @@ uf::stl::string uf::asset::cache( uf::asset::Payload& payload ) {
|
||||
}
|
||||
#if UF_ENV_DREAMCAST
|
||||
UF_MSG_DEBUG("Preloading {}", filename);
|
||||
DC_STATS();
|
||||
// DC_STATS();
|
||||
#endif
|
||||
return payload.filename = filename;
|
||||
}
|
||||
@ -346,7 +347,7 @@ uf::stl::string uf::asset::load( uf::asset::Payload& payload ) {
|
||||
|
||||
#if UF_ENV_DREAMCAST
|
||||
UF_MSG_DEBUG("Loading {}", filename);
|
||||
DC_STATS();
|
||||
// DC_STATS();
|
||||
#endif
|
||||
|
||||
#define UF_ASSET_REGISTER(type)\
|
||||
@ -359,10 +360,25 @@ uf::stl::string uf::asset::load( uf::asset::Payload& payload ) {
|
||||
case uf::asset::Type::IMAGE: {
|
||||
UF_ASSET_REGISTER(uf::Image)
|
||||
asset.open(filename);
|
||||
|
||||
#if UF_USE_DC_TEXCONV
|
||||
uf::stl::string output = uf::io::directory( filename ) + "/" + uf::io::basename( filename );
|
||||
if ( extension != "dtex" && !uf::io::exists( output + ".dtex" ) ) {
|
||||
pod::Vector2ui size = { 32, 32 };
|
||||
uf::stl::string filter = "linear";
|
||||
uf::stl::string dtexFormat = "auto";
|
||||
|
||||
auto img = asset.scale( size, filter);
|
||||
auto dtex = ext::texconv::convert( img, dtexFormat );
|
||||
ext::texconv::save( dtex, output );
|
||||
UF_MSG_DEBUG("Converting image: {} => {}", filename, output );
|
||||
}
|
||||
#endif
|
||||
} break;
|
||||
case uf::asset::Type::AUDIO: {
|
||||
UF_ASSET_REGISTER(pod::AudioClip)
|
||||
uf::audio::load(asset, filename, true);
|
||||
asset.streamed = payload.metadata["streamed"].as<bool>( asset.streamed );
|
||||
uf::audio::load(asset, filename);
|
||||
} break;
|
||||
case uf::asset::Type::JSON: {
|
||||
UF_ASSET_REGISTER(uf::Serializer)
|
||||
@ -405,7 +421,7 @@ uf::stl::string uf::asset::load( uf::asset::Payload& payload ) {
|
||||
|
||||
#if UF_ENV_DREAMCAST
|
||||
UF_MSG_DEBUG("Loaded {}", filename);
|
||||
DC_STATS();
|
||||
// DC_STATS();
|
||||
#endif
|
||||
|
||||
return payload.filename = filename;
|
||||
|
||||
@ -39,6 +39,8 @@ void ext::AudioEmitterBehavior::initialize( uf::Object& self ) {
|
||||
});
|
||||
|
||||
this->addHook( "sound:Emit.%UID%", [&](ext::json::Value& json){
|
||||
//if ( uf::audio::muted ) return;
|
||||
|
||||
if ( ext::json::isNull(json["volume"]) ) json["volume"] = metadataJson["audio"]["volume"];
|
||||
if ( ext::json::isNull(json["pitch"]) ) json["pitch"] = metadataJson["audio"]["pitch"];
|
||||
if ( ext::json::isNull(json["gain"]) ) json["gain"] = metadataJson["audio"]["gain"];
|
||||
@ -53,7 +55,6 @@ void ext::AudioEmitterBehavior::initialize( uf::Object& self ) {
|
||||
|
||||
uf::stl::string filename = json["filename"].as<uf::stl::string>();
|
||||
bool unique = json["unique"].as<bool>();
|
||||
bool streamed = json["streamed"].as<bool>();
|
||||
|
||||
if ( !uf::asset::has( filename ) ) {
|
||||
auto payload = uf::asset::resolveToPayload(filename, "");
|
||||
@ -62,7 +63,6 @@ void ext::AudioEmitterBehavior::initialize( uf::Object& self ) {
|
||||
}
|
||||
|
||||
pod::AudioClip* clip = &uf::asset::get<pod::AudioClip>( filename );
|
||||
|
||||
pod::AudioSource& source = emitter.emit( filename, clip, unique );
|
||||
|
||||
if ( json["pitch"].is<double>() ) uf::audio::pitch(source, json["pitch"].as<float>());
|
||||
@ -123,6 +123,7 @@ void ext::AudioEmitterBehavior::initialize( uf::Object& self ) {
|
||||
|
||||
auto pload = this->resolveToPayload( filename );
|
||||
pload.metadata["layer"] = payload["layer"];
|
||||
pload.metadata["streamed"] = payload["streamed"].as<bool>(true);
|
||||
|
||||
if ( payload["loop"].is<bool>() ) pload.metadata["loop"] = payload["loop"];
|
||||
if ( payload["notify"].is<bool>() ) pload.metadata["notify"] = payload["notify"];
|
||||
@ -137,7 +138,6 @@ void ext::AudioEmitterBehavior::initialize( uf::Object& self ) {
|
||||
if ( metadata.tracks.count(payload.uri) > 0 || metadata.tracks.count(metadata.current) > 0 ) {
|
||||
auto& track = metadata.tracks[payload.uri];
|
||||
pod::AudioClip* clip = &uf::asset::get<pod::AudioClip>( payload.filename );
|
||||
|
||||
int layer = payload.metadata["layer"].as<int>(1);
|
||||
uf::stl::string channelName = FMT_FORMAT("managed_bgm_channel_{}", layer);
|
||||
|
||||
|
||||
@ -513,7 +513,7 @@ void UF_API uf::initialize() {
|
||||
UF_MSG_DEBUG("Requested {} bytes for entity memory pool: {}", (int) size, uf::Entity::memoryPool.data().memory);
|
||||
}
|
||||
}
|
||||
uf::allocator::override = configMemoryPoolJson["override"].as( uf::allocator::override );
|
||||
uf::allocator::override( configMemoryPoolJson["override"].as<bool>() );
|
||||
}
|
||||
|
||||
/* Setup commands */ {
|
||||
@ -685,7 +685,7 @@ void UF_API uf::initialize() {
|
||||
}
|
||||
#endif
|
||||
|
||||
#if UF_USE_OPENAL
|
||||
#if UF_USE_OPENAL || UF_ENV_DREAMCAST
|
||||
/* Initialize OpenAL */ if ( !uf::audio::muted ) {
|
||||
ext::al::initialize();
|
||||
}
|
||||
@ -1055,7 +1055,7 @@ void UF_API uf::terminate() {
|
||||
uf::renderer::destroy();
|
||||
}
|
||||
|
||||
#if UF_USE_OPENAL
|
||||
#if UF_USE_OPENAL || UF_ENV_DREAMCAST
|
||||
/* Initialize OpenAL */ if ( !uf::audio::muted ) {
|
||||
ext::al::destroy();
|
||||
}
|
||||
|
||||
@ -25,7 +25,11 @@
|
||||
|
||||
#include "./payload.h"
|
||||
|
||||
#if UF_USE_OPENGL
|
||||
#define EXT_COLOR_FLOATS 0
|
||||
#else
|
||||
#define EXT_COLOR_FLOATS 1
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
struct GuiVertex {
|
||||
@ -94,24 +98,35 @@ namespace {
|
||||
}
|
||||
|
||||
uf::Mesh& generateMesh( uf::Mesh& mesh, const pod::Vector4f& color, const pod::Vector2f& center ) {
|
||||
#if EXT_COLOR_FLOATS
|
||||
auto& c = color;
|
||||
#else
|
||||
//pod::Vector4ub c = (color * 255);
|
||||
pod::Vector4ub c = {
|
||||
(uint8_t)(color[0] * 255),
|
||||
(uint8_t)(color[1] * 255),
|
||||
(uint8_t)(color[2] * 255),
|
||||
(uint8_t)(color[3] * 255),
|
||||
};
|
||||
#endif
|
||||
mesh.bind<::GuiVertex, uint16_t>();
|
||||
mesh.insertVertices<::GuiVertex>({
|
||||
#if UF_USE_OPENGL
|
||||
{ pod::Vector3f{-1.0f, 1.0f, 0.0f} - center, pod::Vector2f{0.0f, 0.0f}, color },
|
||||
{ pod::Vector3f{-1.0f, -1.0f, 0.0f} - center, pod::Vector2f{0.0f, 1.0f}, color },
|
||||
{ pod::Vector3f{ 1.0f, -1.0f, 0.0f} - center, pod::Vector2f{1.0f, 1.0f}, color },
|
||||
{ pod::Vector3f{-1.0f, 1.0f, 0.0f} - center, pod::Vector2f{0.0f, 0.0f}, c },
|
||||
{ pod::Vector3f{-1.0f, -1.0f, 0.0f} - center, pod::Vector2f{0.0f, 1.0f}, c },
|
||||
{ pod::Vector3f{ 1.0f, -1.0f, 0.0f} - center, pod::Vector2f{1.0f, 1.0f}, c },
|
||||
|
||||
{ pod::Vector3f{ 1.0f, -1.0f, 0.0f} - center, pod::Vector2f{1.0f, 1.0f}, color },
|
||||
{ pod::Vector3f{ 1.0f, 1.0f, 0.0f} - center, pod::Vector2f{1.0f, 0.0f}, color },
|
||||
{ pod::Vector3f{-1.0f, 1.0f, 0.0f} - center, pod::Vector2f{0.0f, 0.0f}, color },
|
||||
{ pod::Vector3f{ 1.0f, -1.0f, 0.0f} - center, pod::Vector2f{1.0f, 1.0f}, c },
|
||||
{ pod::Vector3f{ 1.0f, 1.0f, 0.0f} - center, pod::Vector2f{1.0f, 0.0f}, c },
|
||||
{ pod::Vector3f{-1.0f, 1.0f, 0.0f} - center, pod::Vector2f{0.0f, 0.0f}, c },
|
||||
#else
|
||||
{ pod::Vector3f{-1.0f, 1.0f, 0.0f}, pod::Vector2f{0.0f, 0.0f}, color, center },
|
||||
{ pod::Vector3f{-1.0f, -1.0f, 0.0f}, pod::Vector2f{0.0f, 1.0f}, color, center },
|
||||
{ pod::Vector3f{ 1.0f, -1.0f, 0.0f}, pod::Vector2f{1.0f, 1.0f}, color, center },
|
||||
{ pod::Vector3f{-1.0f, 1.0f, 0.0f}, pod::Vector2f{0.0f, 0.0f}, c, center },
|
||||
{ pod::Vector3f{-1.0f, -1.0f, 0.0f}, pod::Vector2f{0.0f, 1.0f}, c, center },
|
||||
{ pod::Vector3f{ 1.0f, -1.0f, 0.0f}, pod::Vector2f{1.0f, 1.0f}, c, center },
|
||||
|
||||
{ pod::Vector3f{ 1.0f, -1.0f, 0.0f}, pod::Vector2f{1.0f, 1.0f}, color, center },
|
||||
{ pod::Vector3f{ 1.0f, 1.0f, 0.0f}, pod::Vector2f{1.0f, 0.0f}, color, center },
|
||||
{ pod::Vector3f{-1.0f, 1.0f, 0.0f}, pod::Vector2f{0.0f, 0.0f}, color, center },
|
||||
{ pod::Vector3f{ 1.0f, -1.0f, 0.0f}, pod::Vector2f{1.0f, 1.0f}, c, center },
|
||||
{ pod::Vector3f{ 1.0f, 1.0f, 0.0f}, pod::Vector2f{1.0f, 0.0f}, c, center },
|
||||
{ pod::Vector3f{-1.0f, 1.0f, 0.0f}, pod::Vector2f{0.0f, 0.0f}, c, center },
|
||||
#endif
|
||||
});
|
||||
mesh.insertIndices<uint16_t>({
|
||||
|
||||
@ -108,7 +108,7 @@ void ext::LightBehavior::initialize( uf::Object& self ) {
|
||||
UF_BEHAVIOR_METADATA_BIND_SERIALIZER_HOOKS(metadata, metadataJson);
|
||||
}
|
||||
void ext::LightBehavior::tick( uf::Object& self ) {
|
||||
#if !UF_ENV_DREAMCAST
|
||||
#if !UF_USE_OPENGL
|
||||
auto& metadata = this->getComponent<ext::LightBehavior::Metadata>();
|
||||
auto& metadataJson = this->getComponent<uf::Serializer>();
|
||||
if ( this->hasComponent<uf::renderer::RenderTargetRenderMode>() ) {
|
||||
|
||||
515
engine/src/ext/aica/aica.cpp
Normal file
515
engine/src/ext/aica/aica.cpp
Normal file
@ -0,0 +1,515 @@
|
||||
#include <uf/config.h>
|
||||
|
||||
#if UF_ENV_DREAMCAST && UF_USE_AICA
|
||||
#include <uf/ext/aica/aica.h>
|
||||
#include <kos.h>
|
||||
#include <dc/sound/sound.h>
|
||||
#include <dc/sound/sfxmgr.h>
|
||||
#include <uf/utils/memory/pool.h>
|
||||
#include <uf/utils/string/io.h>
|
||||
#include <uf/utils/audio/audio.h>
|
||||
#include <math.h>
|
||||
#include <kos/mutex.h>
|
||||
#include <dc/cache.h>
|
||||
|
||||
#define UF_AICA_THREADED 0
|
||||
|
||||
namespace impl {
|
||||
typedef int (*fill_callback_t)(void* user_data, uint8_t* buffer, int req_bytes);
|
||||
|
||||
constexpr int STREAM_BUFFER_SIZE = 16384;
|
||||
constexpr size_t MAX_VIRTUAL_SOURCES = 256;
|
||||
constexpr size_t MAX_VIRTUAL_BUFFERS = 1024;
|
||||
|
||||
struct Source {
|
||||
bool active = false;
|
||||
|
||||
pod::Vector3f position = {0, 0, 0};
|
||||
float gain = 1;
|
||||
float pitch = 1;
|
||||
float max_distance = 100;
|
||||
bool looping = false;
|
||||
int state = AL_STOPPED;
|
||||
ALuint buffer_id = 0;
|
||||
};
|
||||
|
||||
struct Buffer {
|
||||
bool active = false;
|
||||
uint32_t aica_addr = 0;
|
||||
snd_stream_hnd_t stream_hnd = SND_STREAM_INVALID;
|
||||
|
||||
void* user_data = nullptr;
|
||||
uint8_t* stream_buffer = nullptr;
|
||||
impl::fill_callback_t fill_callback = nullptr;
|
||||
|
||||
ALenum format = 0;
|
||||
ALsizei size = 0;
|
||||
ALsizei frequency = 0;
|
||||
};
|
||||
|
||||
struct Listener {
|
||||
pod::Vector3f position = {0, 0, 0};
|
||||
pod::Vector3f right = {1, 0, 0};
|
||||
} listener;
|
||||
|
||||
impl::Source sources[impl::MAX_VIRTUAL_SOURCES];
|
||||
impl::Buffer buffers[impl::MAX_VIRTUAL_BUFFERS];
|
||||
std::unordered_map<snd_stream_hnd_t, impl::Buffer*> g_activeStreams;
|
||||
mutex_t g_streamMutex = MUTEX_INITIALIZER;
|
||||
|
||||
void* kos_stream_callback( snd_stream_hnd_t hnd, int req_bytes, int* bytes_returned ) {
|
||||
UF_MSG_DEBUG("[AICA] Requesting {} bytes", req_bytes);
|
||||
auto it = g_activeStreams.find(hnd);
|
||||
if ( it == g_activeStreams.end() ) {
|
||||
*bytes_returned = 0;
|
||||
UF_MSG_DEBUG("[AICA] No active stream found: {}", hnd);
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
impl::Buffer* buf = it->second;
|
||||
if ( req_bytes > impl::STREAM_BUFFER_SIZE ) {
|
||||
UF_MSG_WARNING("[AICA] Requesting more than buffer: {} > {}", req_bytes, impl::STREAM_BUFFER_SIZE);
|
||||
req_bytes = impl::STREAM_BUFFER_SIZE;
|
||||
}
|
||||
|
||||
// generate a sin wave for testing
|
||||
// washdc plays this, albeit slowly because emulation speed is hindered
|
||||
// flycast doesn't play audio, this callback gets called twice then never again
|
||||
#if 1
|
||||
float frequency = 440.0f;
|
||||
float sample_rate = buf->frequency > 0 ? buf->frequency : 44100.0f;
|
||||
int channels = (buf->format == AL_FORMAT_STEREO16 || buf->format == AL_FORMAT_STEREO8) ? 2 : 1;
|
||||
|
||||
int16_t* samples = (int16_t*)buf->stream_buffer;
|
||||
int num_samples = req_bytes / sizeof(int16_t);
|
||||
int half_period = (int)(sample_rate / (frequency * 2.0f));
|
||||
static int sample_count = 0;
|
||||
|
||||
for( int i = 0; i < num_samples; i += channels ) {
|
||||
int16_t sample_val = ((sample_count / half_period) % 2 == 0) ? 16000 : -16000;
|
||||
|
||||
samples[i] = sample_val;
|
||||
if ( channels == 2 ) samples[i + 1] = sample_val;
|
||||
sample_count++;
|
||||
}
|
||||
|
||||
*bytes_returned = req_bytes;
|
||||
#else
|
||||
if ( buf->fill_callback && buf->user_data ) {
|
||||
*bytes_returned = buf->fill_callback(buf->user_data, buf->stream_buffer, req_bytes);
|
||||
} else {
|
||||
*bytes_returned = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( *bytes_returned == 0 ) return nullptr;
|
||||
|
||||
return buf->stream_buffer;
|
||||
}
|
||||
|
||||
uint32_t getSourceIndex() {
|
||||
for ( size_t i = 1; i < impl::MAX_VIRTUAL_SOURCES; ++i ) {
|
||||
if ( !impl::sources[i].active ) {
|
||||
impl::sources[i].active = true;
|
||||
impl::sources[i].state = AL_STOPPED;
|
||||
UF_MSG_DEBUG("Assigning index: {}", i);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
uint32_t getBufferIndex() {
|
||||
for ( size_t i = 1; i < impl::MAX_VIRTUAL_BUFFERS; ++i ) {
|
||||
if ( !impl::buffers[i].active ) {
|
||||
impl::buffers[i].active = true;
|
||||
UF_MSG_DEBUG("Assigning index: {}", i);
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
#if UF_AICA_THREADED
|
||||
kthread_t* thread_handle = nullptr;
|
||||
|
||||
// to-do: pipe into uf::thread instead?
|
||||
void* audio_thread( void* param ) {
|
||||
while ( true ) {
|
||||
mutex_lock( &impl::g_streamMutex );
|
||||
for ( auto& pair : impl::g_activeStreams ) {
|
||||
// to-do: check if playing
|
||||
int status = snd_stream_poll(pair.first);
|
||||
if ( status < 0 ) {
|
||||
// to-do: set source to stopped
|
||||
}
|
||||
}
|
||||
mutex_unlock( &impl::g_streamMutex );
|
||||
thd_sleep(50);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ext::al::initialize() {
|
||||
snd_init();
|
||||
snd_stream_init();
|
||||
#if UF_AICA_THREADED
|
||||
impl::thread_handle = thd_create(0, impl::audio_thread, NULL);
|
||||
#endif
|
||||
|
||||
UF_MSG_DEBUG("Initialized AICA.");
|
||||
}
|
||||
|
||||
void ext::al::destroy() {
|
||||
snd_shutdown();
|
||||
}
|
||||
|
||||
uf::stl::string ext::al::getError( ALenum error ) {
|
||||
return "AL_NO_ERROR";
|
||||
}
|
||||
|
||||
void ext::al::Listener::set( ALenum name, ALfloat x, ALfloat y, ALfloat z ) {
|
||||
if ( name == AL_POSITION ) {
|
||||
impl::listener.position = { x, y, z };
|
||||
}
|
||||
}
|
||||
|
||||
void ext::al::Listener::set( ALenum name, const ALfloat* values ) {
|
||||
if ( name == AL_ORIENTATION ) {
|
||||
pod::Vector3f forward{values[0], values[1], values[2]};
|
||||
pod::Vector3f up{values[3], values[4], values[5]};
|
||||
|
||||
impl::listener.right = uf::vector::normalize(uf::vector::cross(forward, up));
|
||||
}
|
||||
}
|
||||
|
||||
pod::Vector3f ext::al::Listener::getPosition() {
|
||||
return impl::listener.position;
|
||||
}
|
||||
pod::Vector3f ext::al::Listener::getRight() {
|
||||
return impl::listener.right;
|
||||
}
|
||||
|
||||
void ext::al::Source::initialize() {
|
||||
if ( this->m_index ) this->destroy();
|
||||
this->m_index = impl::getSourceIndex();
|
||||
}
|
||||
|
||||
void ext::al::Source::destroy() {
|
||||
if ( 0 < this->m_index && this->m_index < impl::MAX_VIRTUAL_SOURCES ) {
|
||||
impl::Source& src = impl::sources[this->m_index];
|
||||
src.active = false;
|
||||
}
|
||||
this->m_index = 0;
|
||||
}
|
||||
|
||||
ALuint& ext::al::Source::getIndex() { return this->m_index; }
|
||||
ALuint ext::al::Source::getIndex() const { return this->m_index; }
|
||||
|
||||
void ext::al::Source::set( ALenum name, ALfloat x, ALfloat y, ALfloat z ) {
|
||||
if ( !this->m_index ) return;
|
||||
impl::Source& src = impl::sources[this->m_index];
|
||||
if ( name == AL_POSITION ) {
|
||||
src.position = { x, y, z };
|
||||
}
|
||||
}
|
||||
|
||||
void ext::al::Source::set( ALenum name, ALfloat x ) {
|
||||
if ( !this->m_index ) return;
|
||||
impl::Source& src = impl::sources[this->m_index];
|
||||
if ( name == AL_GAIN ) src.gain = x;
|
||||
else if ( name == AL_MAX_DISTANCE ) src.max_distance = x;
|
||||
else if ( name == AL_PITCH ) src.pitch = x;
|
||||
}
|
||||
|
||||
void ext::al::Source::set( ALenum name, ALint x ) {
|
||||
if ( !this->m_index ) return;
|
||||
impl::Source& src = impl::sources[this->m_index];
|
||||
if ( name == AL_SOURCE_STATE ) src.state = (int)(x);
|
||||
else if ( name == AL_LOOPING ) src.looping = (x != 0);
|
||||
else if ( name == AL_BUFFER ) src.buffer_id = x;
|
||||
}
|
||||
|
||||
void ext::al::Source::get( ALenum name, ALfloat& x ) const {
|
||||
x = 0.0f;
|
||||
if ( !this->m_index ) return;
|
||||
if ( name == AL_GAIN ) x = impl::sources[this->m_index].gain;
|
||||
else if ( name == AL_PITCH ) x = impl::sources[this->m_index].pitch;
|
||||
else if ( name == AL_MAX_DISTANCE ) x = impl::sources[this->m_index].max_distance;
|
||||
}
|
||||
|
||||
void ext::al::Source::get( ALenum name, ALint& x ) const {
|
||||
x = 0;
|
||||
if ( !this->m_index ) return;
|
||||
if ( name == AL_SOURCE_STATE ) x = impl::sources[this->m_index].state;
|
||||
else if ( name == AL_LOOPING ) x = impl::sources[this->m_index].looping ? 1 : 0;
|
||||
else if ( name == AL_BUFFER ) x = impl::sources[this->m_index].buffer_id;
|
||||
}
|
||||
|
||||
void ext::al::Source::get( ALenum name, ALint* f ) const {
|
||||
if ( f ) this->get( name, f[0] );
|
||||
}
|
||||
|
||||
void ext::al::Source::set( ALenum name, ALint x, ALint y, ALint z ) {
|
||||
// ...
|
||||
}
|
||||
|
||||
void ext::al::Source::set( const uf::stl::string& string, ALfloat x, ALfloat y, ALfloat z ) {
|
||||
if ( string == "POSITION" ) this->set( AL_POSITION, x, y, z );
|
||||
}
|
||||
void ext::al::Source::set( const uf::stl::string& string, ALfloat x ) {
|
||||
if ( string == "GAIN" ) this->set( AL_GAIN, x );
|
||||
if ( string == "MAX_DISTANCE" ) this->set( AL_MAX_DISTANCE, x );
|
||||
if ( string == "PITCH" ) this->set( AL_PITCH, x );
|
||||
}
|
||||
void ext::al::Source::set( const uf::stl::string& string, ALint x ) {
|
||||
if ( string == "SOURCE_STATE" && this->m_index ) this->set( AL_SOURCE_STATE, x );
|
||||
else if ( string == "LOOPING" ) this->set( AL_LOOPING, x );
|
||||
else if ( string == "BUFFER" ) this->set( AL_BUFFER, x );
|
||||
}
|
||||
|
||||
void ext::al::Source::play() {
|
||||
if ( !this->m_index ) return;
|
||||
impl::Source& src = impl::sources[this->m_index];
|
||||
src.state = AL_PLAYING;
|
||||
|
||||
if ( 0 < src.buffer_id && src.buffer_id < impl::MAX_VIRTUAL_BUFFERS ) {
|
||||
impl::Buffer& buffer = impl::buffers[src.buffer_id];
|
||||
|
||||
int vol = 255; // (int)(255.0f * src.gain);
|
||||
int pan = 128;
|
||||
|
||||
if ( buffer.aica_addr != 0 ) {
|
||||
snd_sfx_play(buffer.aica_addr, vol, pan);
|
||||
} else if ( buffer.stream_hnd != SND_STREAM_INVALID ) {
|
||||
int channels = (buffer.format == AL_FORMAT_STEREO16 || buffer.format == AL_FORMAT_STEREO8) ? 1 : 0;
|
||||
|
||||
mutex_lock(&impl::g_streamMutex);
|
||||
|
||||
snd_stream_reinit(buffer.stream_hnd, impl::kos_stream_callback);
|
||||
snd_stream_start(buffer.stream_hnd, buffer.frequency, channels);
|
||||
snd_stream_volume(buffer.stream_hnd, vol);
|
||||
/*
|
||||
snd_stream_reinit(buffer.stream_hnd, impl::kos_stream_callback);
|
||||
snd_stream_queue_enable(buffer.stream_hnd);
|
||||
snd_stream_start(buffer.stream_hnd, buffer.frequency, channels);
|
||||
snd_stream_queue_go(buffer.stream_hnd);
|
||||
snd_stream_volume(buffer.stream_hnd, vol);
|
||||
*/
|
||||
|
||||
mutex_unlock(&impl::g_streamMutex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ext::al::Source::pause() {
|
||||
if ( !this->m_index ) return;
|
||||
impl::Source& src = impl::sources[this->m_index];
|
||||
src.state = AL_PAUSED;
|
||||
|
||||
if ( 0 < src.buffer_id && src.buffer_id < impl::MAX_VIRTUAL_BUFFERS ) {
|
||||
impl::Buffer& buffer = impl::buffers[src.buffer_id];
|
||||
|
||||
if ( buffer.aica_addr != 0 ) {
|
||||
// ...
|
||||
} else if ( buffer.stream_hnd != SND_STREAM_INVALID ) {
|
||||
snd_stream_stop(buffer.stream_hnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ext::al::Source::stop() {
|
||||
if (!this->m_index) return;
|
||||
impl::Source& src = impl::sources[this->m_index];
|
||||
src.state = AL_STOPPED;
|
||||
|
||||
if ( 0 < src.buffer_id && src.buffer_id < impl::MAX_VIRTUAL_BUFFERS ) {
|
||||
impl::Buffer& buffer = impl::buffers[src.buffer_id];
|
||||
|
||||
if ( buffer.aica_addr != 0 ) {
|
||||
// ...
|
||||
} else if ( buffer.stream_hnd != SND_STREAM_INVALID ) {
|
||||
snd_stream_stop(buffer.stream_hnd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool ext::al::Source::playing() const {
|
||||
if ( !this->m_index ) return false;
|
||||
return impl::sources[this->m_index].state == AL_PLAYING;
|
||||
}
|
||||
|
||||
// to-do: implement queueing
|
||||
void ext::al::Source::queue( ALsizei n, ALuint* indices ) {
|
||||
//AL_CHECK_RESULT(alSourceQueueBuffers(this->m_index, n, indices));
|
||||
}
|
||||
void ext::al::Source::unqueue( ALsizei n, ALuint* indices ) {
|
||||
//AL_CHECK_RESULT(alSourceUnqueueBuffers(this->m_index, n, indices));
|
||||
}
|
||||
|
||||
bool ext::al::Buffer::initialized() const {
|
||||
return !this->m_indices.empty();
|
||||
}
|
||||
|
||||
void ext::al::Buffer::initialize( size_t size ) {
|
||||
if ( this->initialized() ) this->destroy();
|
||||
this->m_indices.resize(size, 0);
|
||||
for ( auto i = 0; i < size; ++i ) {
|
||||
this->m_indices[i] = impl::getBufferIndex();
|
||||
}
|
||||
}
|
||||
|
||||
void ext::al::Buffer::destroy() {
|
||||
if ( this->initialized() ) {
|
||||
for ( size_t i = 0; i < this->m_indices.size(); i++ ) {
|
||||
ALuint index = this->m_indices[i];
|
||||
if ( 0 < index && index < impl::MAX_VIRTUAL_BUFFERS ) {
|
||||
impl::Buffer& buffer = impl::buffers[index];
|
||||
|
||||
if ( buffer.aica_addr ) {
|
||||
snd_mem_free( buffer.aica_addr );
|
||||
} else if ( buffer.stream_hnd != SND_STREAM_INVALID ) {
|
||||
mutex_lock(&impl::g_streamMutex);
|
||||
impl::g_activeStreams.erase(buffer.stream_hnd);
|
||||
mutex_unlock(&impl::g_streamMutex);
|
||||
|
||||
snd_stream_destroy( buffer.stream_hnd );
|
||||
}
|
||||
|
||||
if ( buffer.stream_buffer ) {
|
||||
free(buffer.stream_buffer);
|
||||
buffer.stream_buffer = nullptr;
|
||||
}
|
||||
|
||||
buffer.active = false;
|
||||
buffer.aica_addr = 0;
|
||||
buffer.stream_hnd = SND_STREAM_INVALID;
|
||||
buffer.fill_callback = nullptr;
|
||||
buffer.user_data = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
this->m_indices.clear();
|
||||
}
|
||||
|
||||
ALuint& ext::al::Buffer::getIndex( size_t i ) { return this->m_indices[i]; }
|
||||
ALuint ext::al::Buffer::getIndex( size_t i ) const { return this->m_indices[i]; }
|
||||
|
||||
void ext::al::Buffer::poll( size_t i ) {
|
||||
#if !UF_AICA_THREADED
|
||||
if ( !this->initialized() ) return;
|
||||
ALuint index = this->m_indices[i];
|
||||
if ( 0 < index && index < impl::MAX_VIRTUAL_BUFFERS ) {
|
||||
impl::Buffer& buffer = impl::buffers[index];
|
||||
if ( buffer.stream_hnd == SND_STREAM_INVALID ) return;
|
||||
|
||||
// to-do: adjust volume based on distance / pan based on orientation
|
||||
|
||||
int poll_result = snd_stream_poll( buffer.stream_hnd );
|
||||
if ( poll_result < 0 ) UF_MSG_ERROR("[AICA] snd_stream_poll({}) failed with code: {}", buffer.stream_hnd, poll_result);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ext::al::Buffer::set( ALenum name, ALint value, size_t i ) {
|
||||
if ( !this->initialized() ) return;
|
||||
ALuint index = this->m_indices[i];
|
||||
if ( 0 < index && index < impl::MAX_VIRTUAL_BUFFERS ) {
|
||||
impl::Buffer& buffer = impl::buffers[index];
|
||||
|
||||
if ( name == AL_STREAM_HANDLE ) buffer.stream_hnd = (snd_stream_hnd_t)(value);
|
||||
}
|
||||
}
|
||||
|
||||
void ext::al::Buffer::get( ALenum name, ALint& value, size_t i ) const {
|
||||
if ( !this->initialized() ) return;
|
||||
ALuint index = this->m_indices[i];
|
||||
|
||||
if ( 0 < index && index < impl::MAX_VIRTUAL_BUFFERS ) {
|
||||
const impl::Buffer& buffer = impl::buffers[index];
|
||||
|
||||
if ( name == AL_STREAM_HANDLE ) value = (ALint)(buffer.stream_hnd);
|
||||
}
|
||||
}
|
||||
|
||||
void ext::al::Buffer::set( ALenum name, ALint* iv, size_t i ) {
|
||||
//AL_CHECK_RESULT(alBufferiv( this->m_indices[i], name, iv ));
|
||||
|
||||
if ( !this->initialized() ) this->initialize(1);
|
||||
ALuint index = this->m_indices[i];
|
||||
|
||||
if ( 0 < index && index < impl::MAX_VIRTUAL_BUFFERS ) {
|
||||
impl::Buffer& buffer = impl::buffers[index];
|
||||
if ( name == AL_STREAM_FILL_CALLBACK ) buffer.fill_callback = (impl::fill_callback_t)(iv);
|
||||
else if ( name == AL_STREAM_USER_DATA ) buffer.user_data = (void*)(iv);
|
||||
}
|
||||
}
|
||||
void ext::al::Buffer::buffer( ALenum format, const ALvoid* data, ALsizei size, ALsizei frequency, size_t i ) {
|
||||
if ( !this->initialized() ) this->initialize();
|
||||
ext::al::Buffer::buffer( this->m_indices[i], format, data, size, frequency );
|
||||
}
|
||||
// to-do: pick between snd_sfx_* backend (non-streamed) or snd_stream_* (streamed)
|
||||
void ext::al::Buffer::buffer( ALuint index, ALenum format, const ALvoid* data, ALsizei size, ALsizei frequency ) {
|
||||
impl::Buffer& buffer = impl::buffers[index];
|
||||
|
||||
if ( buffer.aica_addr ) {
|
||||
snd_mem_free(buffer.aica_addr);
|
||||
buffer.aica_addr = 0;
|
||||
}
|
||||
if ( buffer.stream_hnd != SND_STREAM_INVALID ) {
|
||||
snd_stream_destroy(buffer.stream_hnd);
|
||||
}
|
||||
|
||||
buffer.format = format;
|
||||
buffer.frequency = frequency;
|
||||
buffer.size = size;
|
||||
|
||||
if ( buffer.fill_callback ) {
|
||||
if ( !buffer.stream_buffer ) buffer.stream_buffer = (uint8_t*)(memalign(32, impl::STREAM_BUFFER_SIZE));
|
||||
if ( !buffer.stream_buffer ) {
|
||||
UF_MSG_ERROR("[AICA] Failed to allocate {} bytes", impl::STREAM_BUFFER_SIZE);
|
||||
return;
|
||||
}
|
||||
buffer.stream_hnd = snd_stream_alloc( impl::kos_stream_callback, impl::STREAM_BUFFER_SIZE );
|
||||
if ( buffer.stream_hnd == SND_STREAM_INVALID ) {
|
||||
UF_MSG_ERROR("[AICA] Failed to allocate {} bytes", impl::STREAM_BUFFER_SIZE);
|
||||
return;
|
||||
}
|
||||
mutex_lock(&impl::g_streamMutex);
|
||||
impl::g_activeStreams[buffer.stream_hnd] = &buffer;
|
||||
mutex_unlock(&impl::g_streamMutex);
|
||||
} else if ( data && size ) {
|
||||
uint32_t aica_addr = snd_mem_malloc(size);
|
||||
if ( !aica_addr ) {
|
||||
UF_MSG_ERROR("[AICA] Failed to allocate {} bytes", size);
|
||||
return;
|
||||
}
|
||||
spu_memload(aica_addr, (void*)(data), size);
|
||||
buffer.aica_addr = aica_addr;
|
||||
UF_MSG_DEBUG("[AICA] Buffer ID {} allocated {} bytes at SPU addr 0x{:X}", index, size, aica_addr);
|
||||
} else {
|
||||
UF_EXCEPTION("[AICA] invalid invocation");
|
||||
}
|
||||
}
|
||||
|
||||
// stubbed
|
||||
void ext::al::Filter::initialize() {}
|
||||
void ext::al::Filter::destroy() {}
|
||||
ALuint ext::al::Filter::getIndex() const { return 0; }
|
||||
void ext::al::Filter::set( ALenum name, ALfloat x ) {}
|
||||
void ext::al::Filter::set( ALenum name, ALint x ) {}
|
||||
|
||||
void ext::al::Effect::initialize() {}
|
||||
void ext::al::Effect::destroy() {}
|
||||
ALuint ext::al::Effect::getIndex() const { return 0; }
|
||||
void ext::al::Effect::set( ALenum name, ALfloat x ) {}
|
||||
void ext::al::Effect::set( ALenum name, ALint x ) {}
|
||||
|
||||
void ext::al::EffectSlot::initialize() {}
|
||||
void ext::al::EffectSlot::destroy() {}
|
||||
ALuint ext::al::EffectSlot::getIndex() const { return 0; }
|
||||
void ext::al::EffectSlot::set( ALenum name, ALfloat x ) {}
|
||||
void ext::al::EffectSlot::set( ALenum name, ALint x ) {}
|
||||
|
||||
#endif
|
||||
@ -1,13 +1,50 @@
|
||||
#include <uf/config.h>
|
||||
#if UF_USE_WAV
|
||||
#if UF_USE_PCM
|
||||
|
||||
#if UF_USE_OPENAL
|
||||
#include <uf/ext/openal/openal.h>
|
||||
#endif
|
||||
#if UF_USE_AICA
|
||||
#include <uf/ext/aica/aica.h>
|
||||
#endif
|
||||
|
||||
#include <uf/ext/audio/pcm.h>
|
||||
#include <uf/utils/memory/pool.h>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
namespace {
|
||||
namespace funs {
|
||||
int fill_buffer(void* user_data, uint8_t* buffer, int req_bytes) {
|
||||
pod::AudioSource* source = (pod::AudioSource*)user_data;
|
||||
pod::AudioClip* clip = source->clip;
|
||||
|
||||
uint8_t* pcm_data = (uint8_t*)clip->stream.buffer;
|
||||
size_t frameSize = clip->info.channels * sizeof(int16_t);
|
||||
|
||||
int totalRead = 0;
|
||||
while ( totalRead < req_bytes ) {
|
||||
size_t bytesLeft = clip->info.size - source->streamState.consumed;
|
||||
size_t bytesToCopy = std::min((size_t)(req_bytes - totalRead), bytesLeft);
|
||||
|
||||
if ( bytesToCopy > 0 ) {
|
||||
std::memcpy(buffer + totalRead, pcm_data + source->streamState.consumed, bytesToCopy);
|
||||
totalRead += (int)bytesToCopy;
|
||||
source->streamState.consumed += bytesToCopy;
|
||||
}
|
||||
|
||||
if ( source->streamState.consumed >= clip->info.size ) {
|
||||
if ( source->settings.loop ) {
|
||||
source->streamState.consumed = clip->info.loop.has ? (clip->info.loop.start * frameSize) : 0;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return totalRead;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ext::pcm::load( pod::AudioClip& clip, const pod::PCM& pcm ) {
|
||||
clip.info.channels = pcm.channels;
|
||||
@ -27,7 +64,7 @@ void ext::pcm::load( pod::AudioClip& clip, const pod::PCM& pcm ) {
|
||||
clip.alBuffer.buffer(clip.info.format, pcm.samples.data(), (ALsizei) clip.info.size, clip.info.frequency);
|
||||
} else {
|
||||
clip.stream.buffer = malloc( clip.info.size ); // to-do: memory pool
|
||||
memcpy( clip.stream.buffer, pcm.samples.data(), clip.info.size );
|
||||
std::memcpy( clip.stream.buffer, pcm.samples.data(), clip.info.size );
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,86 +75,102 @@ void ext::pcm::open( pod::AudioSource& source ) {
|
||||
source.streamBuffers.initialize( source.settings.buffers );
|
||||
source.streamState.consumed = 0;
|
||||
|
||||
int16_t* pcm16 = (int16_t*) clip->stream.buffer;
|
||||
size_t frameSize = clip->info.channels * sizeof(int16_t);
|
||||
size_t totalFrames = clip->info.size / frameSize;
|
||||
size_t bufferFrames = uf::audio::bufferSize / frameSize;
|
||||
|
||||
#if UF_USE_AICA
|
||||
source.streamBuffers.set( AL_STREAM_FILL_CALLBACK, (ALint)(funs::fill_buffer) );
|
||||
source.streamBuffers.set( AL_STREAM_USER_DATA, (ALint*)(&source) );
|
||||
source.streamBuffers.buffer( clip->info.format, NULL, 0, clip->info.frequency );
|
||||
source.alSource.set(AL_BUFFER, (ALint)(source.streamBuffers.getIndex(0)));
|
||||
#else
|
||||
uint8_t buffer[uf::audio::bufferSize];
|
||||
uint8_t queuedBuffers = 0;
|
||||
size_t offset = 0;
|
||||
|
||||
for ( ; queuedBuffers < source.settings.buffers; ++queuedBuffers ) {
|
||||
size_t framesToRead = std::min(bufferFrames, totalFrames - offset);
|
||||
size_t bytesToRead = framesToRead * frameSize;
|
||||
int totalRead = funs::fill_buffer(&source, buffer, uf::audio::bufferSize);
|
||||
if ( totalRead == 0 ) break;
|
||||
|
||||
if ( framesToRead == 0 ) {
|
||||
if (source.settings.loop) {
|
||||
offset = 0;
|
||||
framesToRead = std::min(bufferFrames, totalFrames);
|
||||
bytesToRead = framesToRead * frameSize;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
AL_CHECK_RESULT(alBufferData(source.streamBuffers.getIndex(queuedBuffers), clip->info.format, pcm16 + offset * clip->info.channels, (ALsizei)bytesToRead, clip->info.frequency));
|
||||
offset += framesToRead;
|
||||
ext::al::Buffer::buffer( source.streamBuffers.getIndex(queuedBuffers), clip->info.format, buffer, totalRead, clip->info.frequency);
|
||||
}
|
||||
source.streamState.consumed = offset * frameSize;
|
||||
AL_CHECK_RESULT(alSourceQueueBuffers(source.alSource.getIndex(), queuedBuffers, &source.streamBuffers.getIndex(0)));
|
||||
source.alSource.queue( queuedBuffers, &source.streamBuffers.getIndex(0) );
|
||||
|
||||
if ( queuedBuffers >= source.settings.buffers ) {
|
||||
source.settings.loopMode = 1;
|
||||
source.alSource.set(AL_LOOPING, AL_FALSE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ext::pcm::update( pod::AudioSource& source ) {
|
||||
pod::AudioClip* clip = source.clip;
|
||||
if ( !clip ) return;
|
||||
if ( !clip || !clip->streamed || !clip->stream.buffer ) return;
|
||||
|
||||
if ( source.settings.loopMode == 1 ) source.alSource.set(AL_LOOPING, AL_FALSE);
|
||||
#if UF_USE_AICA
|
||||
ALint hnd_val = 0;
|
||||
source.streamBuffers.get( AL_STREAM_HANDLE, hnd_val );
|
||||
snd_stream_hnd_t hnd = (snd_stream_hnd_t)hnd_val;
|
||||
|
||||
if ( hnd == SND_STREAM_INVALID ) return;
|
||||
|
||||
ALint state;
|
||||
source.alSource.get(AL_SOURCE_STATE, state);
|
||||
if ( state != AL_PLAYING ) {
|
||||
if ( !source.settings.loop && source.streamState.consumed >= clip->info.size ) {
|
||||
return;
|
||||
if ( state == AL_PLAYING ) {
|
||||
int poll_result = snd_stream_poll(hnd);
|
||||
if ( poll_result < 0 ) UF_MSG_ERROR("[AICA] snd_stream_poll({}) failed with code: {}", hnd, poll_result);
|
||||
}
|
||||
#else
|
||||
ALint state, processed, queued;
|
||||
source.alSource.get(AL_SOURCE_STATE, state);
|
||||
source.alSource.get(AL_BUFFERS_PROCESSED, processed);
|
||||
source.alSource.get(AL_BUFFERS_QUEUED, queued);
|
||||
|
||||
bool hasData = (source.streamState.consumed < clip->info.size) || source.settings.loop;
|
||||
|
||||
#if !NO_FUN
|
||||
if ( source.settings.loopMode == 1 ) {
|
||||
source.alSource.set(AL_LOOPING, AL_FALSE);
|
||||
}
|
||||
#endif
|
||||
|
||||
auto fillAndQueueBuffer = [&](ALuint index) -> bool {
|
||||
uint8_t buffer[uf::audio::bufferSize];
|
||||
int totalRead = funs::fill_buffer(&source, buffer, uf::audio::bufferSize);
|
||||
|
||||
if ( totalRead > 0 ) {
|
||||
ext::al::Buffer::buffer(index, clip->info.format, buffer, totalRead, clip->info.frequency);
|
||||
source.alSource.queue( 1, &index );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
if ( queued == 0 ) {
|
||||
if ( hasData ) {
|
||||
for ( int i = 0; i < source.settings.buffers; ++i ) {
|
||||
if ( !fillAndQueueBuffer(source.streamBuffers.getIndex(i)) ) break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
while ( processed > 0 ) {
|
||||
ALuint index;
|
||||
source.alSource.unqueue( 1, &index );
|
||||
processed--;
|
||||
|
||||
hasData = (source.streamState.consumed < clip->info.size) || source.settings.loop;
|
||||
if ( hasData ) fillAndQueueBuffer(index);
|
||||
}
|
||||
}
|
||||
|
||||
source.alSource.get(AL_SOURCE_STATE, state);
|
||||
source.alSource.get(AL_BUFFERS_QUEUED, queued);
|
||||
|
||||
if ( state != AL_PLAYING && queued > 0 ) {
|
||||
source.alSource.play();
|
||||
}
|
||||
|
||||
ALint processed = 0;
|
||||
source.alSource.get(AL_BUFFERS_PROCESSED, processed);
|
||||
if ( processed <= 0 ) return;
|
||||
#if !NO_FUN
|
||||
if ( source.settings.loopMode == 1 ) source.alSource.set(AL_LOOPING, AL_FALSE);
|
||||
#endif
|
||||
|
||||
int16_t* pcm16 = (int16_t*) clip->stream.buffer;
|
||||
size_t frameSize = clip->info.channels * sizeof(int16_t);
|
||||
size_t totalFrames = clip->info.size / frameSize;
|
||||
size_t bufferFrames = uf::audio::bufferSize / frameSize;
|
||||
|
||||
ALuint index;
|
||||
while ( processed-- ) {
|
||||
AL_CHECK_RESULT(alSourceUnqueueBuffers(source.alSource.getIndex(), 1, &index));
|
||||
|
||||
size_t offset = source.streamState.consumed / frameSize;
|
||||
size_t framesToRead = std::min(bufferFrames, totalFrames - offset);
|
||||
size_t bytesToRead = framesToRead * frameSize;
|
||||
|
||||
if ( framesToRead == 0 ) {
|
||||
if ( !source.settings.loop ) break;
|
||||
offset = 0;
|
||||
framesToRead = std::min(bufferFrames, totalFrames);
|
||||
bytesToRead = framesToRead * frameSize;
|
||||
}
|
||||
|
||||
if ( framesToRead > 0 ) {
|
||||
AL_CHECK_RESULT(alBufferData(index, clip->info.format, pcm16 + offset * clip->info.channels, (ALsizei)bytesToRead, clip->info.frequency));
|
||||
AL_CHECK_RESULT(alSourceQueueBuffers(source.alSource.getIndex(), 1, &index));
|
||||
source.streamState.consumed = (offset + framesToRead) * frameSize;
|
||||
}
|
||||
}
|
||||
if ( source.settings.loopMode == 1 ) source.alSource.set(AL_LOOPING, AL_TRUE);
|
||||
#endif
|
||||
}
|
||||
|
||||
void ext::pcm::close( pod::AudioClip& clip ) {
|
||||
@ -134,8 +187,9 @@ void ext::pcm::close( pod::AudioSource& source ) {
|
||||
source.alSource.get(AL_BUFFERS_QUEUED, queued);
|
||||
while ( queued-- ) {
|
||||
ALuint buffer;
|
||||
AL_CHECK_RESULT(alSourceUnqueueBuffers(source.alSource.getIndex(), 1, &buffer));
|
||||
source.alSource.unqueue( 1, &buffer );
|
||||
}
|
||||
|
||||
source.streamBuffers.destroy();
|
||||
source.streamState.consumed = 0;
|
||||
}
|
||||
|
||||
@ -5,6 +5,10 @@
|
||||
#include <uf/ext/openal/openal.h>
|
||||
#endif
|
||||
|
||||
#if UF_USE_AICA
|
||||
#include <uf/ext/aica/aica.h>
|
||||
#endif
|
||||
|
||||
#include <uf/ext/audio/vorbis.h>
|
||||
#include <uf/utils/memory/pool.h>
|
||||
#include <uf/utils/io/vfs.h>
|
||||
@ -21,59 +25,100 @@ namespace {
|
||||
constexpr int endian = 0; // 0 = little endian
|
||||
|
||||
struct VorbisVfsContext {
|
||||
uf::stl::string filename;
|
||||
size_t currentOffset;
|
||||
size_t totalSize;
|
||||
pod::File file;
|
||||
|
||||
~VorbisVfsContext() {
|
||||
if ( file ) file.close( file.handle );
|
||||
}
|
||||
};
|
||||
|
||||
namespace funs {
|
||||
size_t read(void* destination, size_t size, size_t nmemb, void* userdata) {
|
||||
VorbisVfsContext* ctx = (VorbisVfsContext*) userdata;
|
||||
size_t bytesToRead = size * nmemb;
|
||||
size_t bytesLeft = ctx->totalSize - ctx->currentOffset;
|
||||
if (bytesToRead > bytesLeft) bytesToRead = bytesLeft;
|
||||
if ( !ctx->file ) return 0;
|
||||
|
||||
if (bytesToRead > 0) {
|
||||
uf::stl::vector<uint8_t> tempBuffer;
|
||||
if (uf::vfs::readRange(ctx->filename, ctx->currentOffset, bytesToRead, tempBuffer)) {
|
||||
std::memcpy(destination, tempBuffer.data(), tempBuffer.size());
|
||||
ctx->currentOffset += tempBuffer.size();
|
||||
return tempBuffer.size() / size;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
size_t bytesRead = ctx->file.read(ctx->file.handle, destination, size * nmemb);
|
||||
return bytesRead / size;
|
||||
}
|
||||
|
||||
int seek( void* userdata, ogg_int64_t to, int type ) {
|
||||
VorbisVfsContext* ctx = (VorbisVfsContext*) userdata;
|
||||
int64_t targetOffset = 0;
|
||||
if ( !ctx->file ) return -1;
|
||||
|
||||
switch ( type ) {
|
||||
case SEEK_CUR: targetOffset = (int64_t)ctx->currentOffset + to; break;
|
||||
case SEEK_END: targetOffset = (int64_t)ctx->totalSize + to; break;
|
||||
case SEEK_SET: targetOffset = to; break;
|
||||
default: return -1;
|
||||
}
|
||||
int whence = SEEK_SET;
|
||||
if ( type == SEEK_CUR ) whence = SEEK_CUR;
|
||||
else if ( type == SEEK_END ) whence = SEEK_END;
|
||||
|
||||
if (targetOffset < 0) targetOffset = 0;
|
||||
if ((size_t)targetOffset > ctx->totalSize) targetOffset = ctx->totalSize;
|
||||
|
||||
ctx->currentOffset = (size_t)targetOffset;
|
||||
return 0;
|
||||
if ( ctx->file.seek(ctx->file.handle, (long)to, whence) ) return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int close(void* userdata) {
|
||||
VorbisVfsContext* ctx = (VorbisVfsContext*) userdata;
|
||||
if (ctx) {
|
||||
delete ctx;
|
||||
}
|
||||
if (ctx) delete ctx;
|
||||
return 0;
|
||||
}
|
||||
|
||||
long tell(void* userdata) {
|
||||
VorbisVfsContext* ctx = (VorbisVfsContext*) userdata;
|
||||
return (long)ctx->currentOffset;
|
||||
if ( !ctx->file ) return -1;
|
||||
return (long)ctx->file.tell(ctx->file.handle);
|
||||
}
|
||||
|
||||
int fill_buffer( pod::AudioSource* source, uint8_t* buffer, int req_bytes ) {
|
||||
pod::AudioClip* clip = source->clip;
|
||||
VorbisVfsContext* ctx = (VorbisVfsContext*)source->streamState.context;
|
||||
OggVorbis_File* vorbisFile = (OggVorbis_File*)source->streamState.handle;
|
||||
|
||||
int totalRead = 0;
|
||||
while ( totalRead < req_bytes ) {
|
||||
int result = OV_READ(vorbisFile, (char*)buffer + totalRead, req_bytes - totalRead, 0, 2, 1, &source->streamState.bitStream);
|
||||
if ( result <= 0 ) {
|
||||
if ( result == 0 ) {
|
||||
if ( !source->info.pending.empty() ) {
|
||||
|
||||
uf::stl::string nextFile = source->info.pending.front();
|
||||
source->info.pending.erase(source->info.pending.begin());
|
||||
|
||||
ov_clear(vorbisFile);
|
||||
|
||||
VorbisVfsContext* nextCtx = new VorbisVfsContext();
|
||||
nextCtx->file = uf::vfs::open(nextFile);
|
||||
|
||||
ov_callbacks callbacks = { funs::read, funs::seek, funs::close, funs::tell };
|
||||
|
||||
if ( ov_open_callbacks((void*) nextCtx, vorbisFile, NULL, -1, callbacks) < 0 ) {
|
||||
UF_MSG_ERROR("Gapless Vorbis transition failed! Could not open: {}", nextFile);
|
||||
delete nextCtx;
|
||||
break;
|
||||
}
|
||||
|
||||
clip->filename = nextFile;
|
||||
nextCtx->file.seek(nextCtx->file.handle, 0, SEEK_END);
|
||||
clip->info.size = nextCtx->file.tell(nextCtx->file.handle);
|
||||
nextCtx->file.seek(nextCtx->file.handle, 0, SEEK_SET);
|
||||
clip->info.duration = ov_time_total(vorbisFile, -1);
|
||||
|
||||
source->info.elapsed = 0.0f;
|
||||
source->info.timer.reset();
|
||||
source->info.timer.start();
|
||||
|
||||
ctx = nextCtx;
|
||||
source->streamState.context = (void*) ctx;
|
||||
continue;
|
||||
}
|
||||
else if ( source->settings.loop ) {
|
||||
uint32_t seekTarget = clip->info.loop.has ? clip->info.loop.start : 0;
|
||||
ov_pcm_seek(vorbisFile, seekTarget);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
totalRead += result;
|
||||
}
|
||||
return totalRead;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool format( pod::AudioClip& clip, int channels, int bitDepth) {
|
||||
@ -97,15 +142,20 @@ void ext::vorbis::open( pod::AudioSource& source ) {
|
||||
source.streamState.consumed = 0;
|
||||
source.streamState.bitStream = 0;
|
||||
|
||||
|
||||
VorbisVfsContext* ctx = new VorbisVfsContext();
|
||||
ctx->filename = clip->filename;
|
||||
ctx->currentOffset = 0;
|
||||
ctx->totalSize = clip->info.size;
|
||||
ctx->file = uf::vfs::open(clip->filename);
|
||||
if ( !ctx->file ) {
|
||||
UF_MSG_ERROR("Vorbis: failed to open file: {}", clip->filename);
|
||||
delete ctx;
|
||||
return;
|
||||
}
|
||||
|
||||
OggVorbis_File* vorbisFile = new OggVorbis_File;
|
||||
ov_callbacks callbacks = { funs::read, funs::seek, funs::close, funs::tell };
|
||||
|
||||
if ( ov_open_callbacks((void*) ctx, vorbisFile, NULL, -1, callbacks) < 0 ) {
|
||||
UF_MSG_ERROR("Vorbis: failed to open file: {}", clip->filename);
|
||||
delete ctx; delete vorbisFile;
|
||||
return;
|
||||
}
|
||||
@ -113,6 +163,16 @@ void ext::vorbis::open( pod::AudioSource& source ) {
|
||||
source.streamState.context = (void*) ctx;
|
||||
source.streamState.handle = (void*) vorbisFile;
|
||||
|
||||
#if UF_USE_AICA
|
||||
UF_MSG_DEBUG("Setting callback");
|
||||
source.streamBuffers.set( AL_STREAM_FILL_CALLBACK, (ALint*)(funs::fill_buffer) );
|
||||
UF_MSG_DEBUG("Setting userdata");
|
||||
source.streamBuffers.set( AL_STREAM_USER_DATA, (ALint*)(&source) );
|
||||
UF_MSG_DEBUG("Setting buffer");
|
||||
source.alSource.set(AL_BUFFER, (ALint)(source.streamBuffers.getIndex(0)));
|
||||
UF_MSG_DEBUG("Initializing buffer");
|
||||
source.streamBuffers.buffer( clip->info.format, NULL, 0, clip->info.frequency );
|
||||
#else
|
||||
char buffer[uf::audio::bufferSize];
|
||||
uint8_t queuedBuffers = 0;
|
||||
for ( ; queuedBuffers < source.settings.buffers; ++queuedBuffers ) {
|
||||
@ -130,23 +190,21 @@ void ext::vorbis::open( pod::AudioSource& source ) {
|
||||
totalRead += result;
|
||||
}
|
||||
if ( totalRead == 0 ) break;
|
||||
AL_CHECK_RESULT(alBufferData(source.streamBuffers.getIndex(queuedBuffers), clip->info.format, buffer, totalRead, clip->info.frequency));
|
||||
ext::al::Buffer::buffer( source.streamBuffers.getIndex(queuedBuffers), clip->info.format, buffer, totalRead, clip->info.frequency );
|
||||
}
|
||||
AL_CHECK_RESULT(alSourceQueueBuffers(source.alSource.getIndex(), queuedBuffers, &source.streamBuffers.getIndex(0)));
|
||||
source.alSource.queue( queuedBuffers, &source.streamBuffers.getIndex(0) );
|
||||
|
||||
if ( queuedBuffers >= source.settings.buffers ) {
|
||||
source.settings.loopMode = 1;
|
||||
source.alSource.set(AL_LOOPING, AL_FALSE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ext::vorbis::load( pod::AudioClip& clip ) {
|
||||
VorbisVfsContext* ctx = new VorbisVfsContext();
|
||||
ctx->filename = clip.filename;
|
||||
ctx->currentOffset = 0;
|
||||
ctx->totalSize = uf::vfs::size(clip.filename);
|
||||
|
||||
if ( ctx->totalSize == 0 ) {
|
||||
ctx->file = uf::vfs::open(clip.filename);
|
||||
if ( !ctx->file ) {
|
||||
UF_MSG_ERROR("Vorbis: failed to open file: {}", clip.filename);
|
||||
delete ctx;
|
||||
return;
|
||||
@ -166,7 +224,10 @@ void ext::vorbis::load( pod::AudioClip& clip ) {
|
||||
clip.info.bitDepth = 16;
|
||||
clip.info.frequency = info->rate;
|
||||
clip.info.duration = ov_time_total(vorbisFile, -1);
|
||||
clip.info.size = ctx->totalSize;
|
||||
|
||||
ctx->file.seek(ctx->file.handle, 0, SEEK_END);
|
||||
clip.info.size = ctx->file.tell(ctx->file.handle);
|
||||
ctx->file.seek(ctx->file.handle, 0, SEEK_SET);
|
||||
|
||||
clip.info.loop.has = false;
|
||||
clip.info.loop.start = 0;
|
||||
@ -206,7 +267,7 @@ void ext::vorbis::load( pod::AudioClip& clip ) {
|
||||
clip.alBuffer.buffer(clip.info.format, bytes.data(), (ALsizei) bytes.size(), clip.info.frequency);
|
||||
if ( clip.info.loop.has ) {
|
||||
ALint loopPoints[2] = { (ALint) clip.info.loop.start, (ALint) clip.info.loop.end };
|
||||
alBufferiv(clip.alBuffer.getIndex(0), 0x2015 /* AL_LOOP_POINTS_SOFT */, loopPoints);
|
||||
clip.alBuffer.set( 0x2015 /* AL_LOOP_POINTS_SOFT */, loopPoints );
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,6 +279,13 @@ void ext::vorbis::update( pod::AudioSource& source ) {
|
||||
pod::AudioClip* clip = source.clip;
|
||||
if ( !clip || !clip->streamed || !source.streamState.handle ) return;
|
||||
|
||||
#if UF_USE_AICA
|
||||
ALint state;
|
||||
source.alSource.get(AL_SOURCE_STATE, state);
|
||||
if ( state == AL_PLAYING ) {
|
||||
source.streamBuffers.poll();
|
||||
}
|
||||
#else
|
||||
OggVorbis_File* vorbisFile = (OggVorbis_File*) source.streamState.handle;
|
||||
VorbisVfsContext* ctx = (VorbisVfsContext*) source.streamState.context;
|
||||
|
||||
@ -226,71 +294,21 @@ void ext::vorbis::update( pod::AudioSource& source ) {
|
||||
source.alSource.get(AL_BUFFERS_PROCESSED, processed);
|
||||
source.alSource.get(AL_BUFFERS_QUEUED, queued);
|
||||
|
||||
bool hasData = (ctx->currentOffset < ctx->totalSize) || !source.info.pending.empty() || source.settings.loop;
|
||||
#if !NO_FUN // if the engine cannot feed buffers, OpenAL will continue to loop the buffers
|
||||
source.alSource.set(AL_LOOPING, hasData ? AL_TRUE : AL_FALSE);
|
||||
#else // consume buffers automatically
|
||||
bool hasData = (ctx->file.tell(ctx->file.handle) < clip->info.size) || !source.info.pending.empty() || source.settings.loop;
|
||||
#if !NO_FUN
|
||||
if ( source.settings.loopMode == 1 ) {
|
||||
source.alSource.set(AL_LOOPING, AL_FALSE);
|
||||
source.settings.loopMode = 0;
|
||||
}
|
||||
#else
|
||||
// source.alSource.set(AL_LOOPING, hasData ? AL_TRUE : AL_FALSE);
|
||||
#endif
|
||||
|
||||
auto fillAndQueueBuffer = [&](ALuint index) -> bool {
|
||||
char buffer[uf::audio::bufferSize];
|
||||
int totalRead = 0;
|
||||
|
||||
while ( totalRead < uf::audio::bufferSize ) {
|
||||
int result = OV_READ(vorbisFile, buffer + totalRead, uf::audio::bufferSize - totalRead, endian, 2, 1, &source.streamState.bitStream);
|
||||
|
||||
if ( result <= 0 ) {
|
||||
if ( result == 0 ) {
|
||||
if ( !source.info.pending.empty() ) {
|
||||
|
||||
uf::stl::string nextFile = source.info.pending.front();
|
||||
source.info.pending.erase(source.info.pending.begin());
|
||||
|
||||
ov_clear(vorbisFile);
|
||||
|
||||
VorbisVfsContext* nextCtx = new VorbisVfsContext();
|
||||
nextCtx->filename = uf::io::resolveURI(nextFile);
|
||||
nextCtx->currentOffset = 0;
|
||||
nextCtx->totalSize = uf::vfs::size(nextCtx->filename);
|
||||
|
||||
ov_callbacks callbacks = { funs::read, funs::seek, funs::close, funs::tell };
|
||||
|
||||
if ( ov_open_callbacks((void*) nextCtx, vorbisFile, NULL, -1, callbacks) < 0 ) {
|
||||
UF_MSG_ERROR("Gapless Vorbis transition failed! Could not open: {}", nextCtx->filename);
|
||||
delete nextCtx;
|
||||
break;
|
||||
}
|
||||
|
||||
clip->filename = nextFile;
|
||||
clip->info.size = nextCtx->totalSize;
|
||||
clip->info.duration = ov_time_total(vorbisFile, -1);
|
||||
|
||||
source.info.elapsed = 0.0f;
|
||||
source.info.timer.reset();
|
||||
source.info.timer.start();
|
||||
|
||||
ctx = nextCtx;
|
||||
source.streamState.context = (void*) ctx;
|
||||
continue;
|
||||
}
|
||||
else if ( source.settings.loop ) {
|
||||
uint32_t seekTarget = clip->info.loop.has ? clip->info.loop.start : 0;
|
||||
ov_pcm_seek(vorbisFile, seekTarget);
|
||||
continue;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
totalRead += result;
|
||||
}
|
||||
|
||||
uint8_t buffer[uf::audio::bufferSize];
|
||||
int totalRead = funs::fill_buffer(&source, buffer, uf::audio::bufferSize);
|
||||
if ( totalRead > 0 ) {
|
||||
AL_CHECK_RESULT(alBufferData(index, clip->info.format, buffer, totalRead, clip->info.frequency));
|
||||
AL_CHECK_RESULT(alSourceQueueBuffers(source.alSource.getIndex(), 1, &index));
|
||||
ext::al::Buffer::buffer(index, clip->info.format, buffer, totalRead, clip->info.frequency);
|
||||
source.alSource.queue( 1, &index );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -305,10 +323,10 @@ void ext::vorbis::update( pod::AudioSource& source ) {
|
||||
} else {
|
||||
while ( processed > 0 ) {
|
||||
ALuint index;
|
||||
AL_CHECK_RESULT(alSourceUnqueueBuffers(source.alSource.getIndex(), 1, &index));
|
||||
source.alSource.unqueue( 1, &index );
|
||||
processed--;
|
||||
|
||||
bool hasData = (ctx->currentOffset < ctx->totalSize) || !source.info.pending.empty() || source.settings.loop;
|
||||
bool hasData = (ctx->file.tell(ctx->file.handle) < clip->info.size) || !source.info.pending.empty() || source.settings.loop;
|
||||
|
||||
if ( hasData ) {
|
||||
fillAndQueueBuffer(index);
|
||||
@ -324,6 +342,12 @@ void ext::vorbis::update( pod::AudioSource& source ) {
|
||||
if ( state != AL_PLAYING && queued > 0 ) {
|
||||
source.alSource.play();
|
||||
}
|
||||
#if !NO_FUN
|
||||
if ( source.settings.loopMode == 1 ) {
|
||||
source.alSource.set(AL_LOOPING, AL_FALSE);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
void ext::vorbis::close( pod::AudioClip& clip ) {
|
||||
// ...
|
||||
@ -335,7 +359,7 @@ void ext::vorbis::close( pod::AudioSource& source ) {
|
||||
source.alSource.get(AL_BUFFERS_QUEUED, queued);
|
||||
while ( queued-- ) {
|
||||
ALuint buffer;
|
||||
alSourceUnqueueBuffers(source.alSource.getIndex(), 1, &buffer);
|
||||
source.alSource.unqueue( 1, &buffer );
|
||||
}
|
||||
source.streamBuffers.destroy();
|
||||
|
||||
|
||||
@ -5,6 +5,10 @@
|
||||
#include <uf/ext/openal/openal.h>
|
||||
#endif
|
||||
|
||||
#if UF_USE_AICA
|
||||
#include <uf/ext/aica/aica.h>
|
||||
#endif
|
||||
|
||||
#include <uf/ext/audio/wav.h>
|
||||
#include <uf/utils/memory/pool.h>
|
||||
#include <uf/utils/io/vfs.h>
|
||||
@ -17,45 +21,88 @@
|
||||
namespace {
|
||||
struct DrWavVfsContext {
|
||||
drwav wav;
|
||||
uf::stl::string filename;
|
||||
size_t currentOffset;
|
||||
size_t totalSize;
|
||||
pod::File file;
|
||||
|
||||
~DrWavVfsContext() {
|
||||
if ( file ) file.close( file.handle );
|
||||
}
|
||||
};
|
||||
|
||||
size_t drwav_vfs_read( void* pUserData, void* pBufferOut, size_t bytesToRead ) {
|
||||
DrWavVfsContext* ctx = (DrWavVfsContext*)pUserData;
|
||||
size_t bytesLeft = ctx->totalSize - ctx->currentOffset;
|
||||
if ( bytesToRead > bytesLeft ) bytesToRead = bytesLeft;
|
||||
|
||||
if ( bytesToRead > 0 ) {
|
||||
uf::stl::vector<uint8_t> tempBuffer;
|
||||
if ( uf::vfs::readRange(ctx->filename, ctx->currentOffset, bytesToRead, tempBuffer) ) {
|
||||
std::memcpy(pBufferOut, tempBuffer.data(), tempBuffer.size());
|
||||
ctx->currentOffset += tempBuffer.size();
|
||||
return tempBuffer.size();
|
||||
}
|
||||
namespace funs {
|
||||
size_t read( void* pUserData, void* pBufferOut, size_t bytesToRead ) {
|
||||
DrWavVfsContext* ctx = (DrWavVfsContext*)pUserData;
|
||||
if ( !ctx->file ) return 0;
|
||||
return ctx->file.read(ctx->file.handle, pBufferOut, bytesToRead);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
drwav_bool32 drwav_vfs_seek( void* pUserData, int offset, drwav_seek_origin origin ) {
|
||||
DrWavVfsContext* ctx = (DrWavVfsContext*)pUserData;
|
||||
long long targetOffset = 0;
|
||||
if ( (int)origin == 0 ) targetOffset = offset;
|
||||
else if ( (int)origin == 1 ) targetOffset = (long long)ctx->currentOffset + offset;
|
||||
else if ( (int)origin == 2 ) targetOffset = (long long)ctx->totalSize + offset;
|
||||
drwav_bool32 seek( void* pUserData, int offset, drwav_seek_origin origin ) {
|
||||
DrWavVfsContext* ctx = (DrWavVfsContext*)pUserData;
|
||||
if ( !ctx->file ) return 0;
|
||||
|
||||
if (targetOffset < 0) targetOffset = 0;
|
||||
if ((size_t)targetOffset > ctx->totalSize) targetOffset = ctx->totalSize;
|
||||
int whence = SEEK_SET;
|
||||
if ( origin == DRWAV_SEEK_CUR ) whence = SEEK_CUR;
|
||||
else if ( origin == DRWAV_SEEK_END ) whence = SEEK_END;
|
||||
|
||||
ctx->currentOffset = (size_t)targetOffset;
|
||||
return 1;
|
||||
}
|
||||
if ( ctx->file.seek(ctx->file.handle, offset, whence) ) return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
drwav_bool32 drwav_vfs_tell( void* pUserData, long long int* pCursor ) {
|
||||
DrWavVfsContext* ctx = (DrWavVfsContext*)pUserData;
|
||||
if (pCursor) *pCursor = (long long int)ctx->currentOffset;
|
||||
return 1;
|
||||
drwav_bool32 tell( void* pUserData, long long int* pCursor ) {
|
||||
DrWavVfsContext* ctx = (DrWavVfsContext*)pUserData;
|
||||
if ( !ctx->file ) return 0;
|
||||
if ( pCursor ) *pCursor = (long long int)ctx->file.tell(ctx->file.handle);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int fill_buffer( void* user_data, uint8_t* buffer, int req_bytes ) {
|
||||
pod::AudioSource* source = (pod::AudioSource*)user_data;
|
||||
pod::AudioClip* clip = source->clip;
|
||||
DrWavVfsContext* ctx = (DrWavVfsContext*)source->streamState.handle;
|
||||
drwav* wav = &ctx->wav;
|
||||
|
||||
size_t frameSize = wav->channels * sizeof(int16_t);
|
||||
drwav_uint64 framesToRead = req_bytes / frameSize;
|
||||
drwav_uint64 totalFramesRead = 0;
|
||||
int16_t* bufferPtr = (int16_t*)buffer;
|
||||
|
||||
while ( totalFramesRead < framesToRead ) {
|
||||
drwav_uint64 framesRead = drwav_read_pcm_frames_s16(wav, framesToRead - totalFramesRead, bufferPtr);
|
||||
|
||||
totalFramesRead += framesRead;
|
||||
bufferPtr += (framesRead * wav->channels);
|
||||
|
||||
if ( framesRead == 0 ) {
|
||||
if ( !source->info.pending.empty() ) {
|
||||
uf::stl::string nextFile = source->info.pending.front();
|
||||
source->info.pending.erase(source->info.pending.begin());
|
||||
|
||||
drwav_uninit(wav);
|
||||
|
||||
if ( ctx->file ) ctx->file.close(ctx->file.handle);
|
||||
ctx->file = uf::vfs::open( nextFile );
|
||||
|
||||
if ( !drwav_init(wav, funs::read, funs::seek, funs::tell, ctx, nullptr) ) {
|
||||
UF_MSG_ERROR("Transition failed! Could not open: {}", nextFile);
|
||||
break;
|
||||
}
|
||||
|
||||
clip->filename = nextFile;
|
||||
clip->info.size = wav->totalPCMFrameCount * wav->channels * sizeof(int16_t);
|
||||
clip->info.duration = (double)wav->totalPCMFrameCount / wav->sampleRate;
|
||||
|
||||
source->info.elapsed = 0.0f;
|
||||
source->info.timer.reset();
|
||||
source->info.timer.start();
|
||||
} else if ( source->settings.loop ) {
|
||||
drwav_seek_to_pcm_frame(wav, clip->info.loop.has ? clip->info.loop.start : 0);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return (int)(totalFramesRead * frameSize);
|
||||
}
|
||||
}
|
||||
|
||||
// default to 16-bit audio
|
||||
@ -72,11 +119,14 @@ namespace {
|
||||
|
||||
void ext::wav::load( pod::AudioClip& clip ) {
|
||||
DrWavVfsContext* ctx = new DrWavVfsContext();
|
||||
ctx->filename = clip.filename;
|
||||
ctx->currentOffset = 0;
|
||||
ctx->totalSize = uf::vfs::size(clip.filename);
|
||||
ctx->file = uf::vfs::open(clip.filename);
|
||||
if ( !ctx->file ) {
|
||||
UF_MSG_ERROR("WAV: failed to open file: {}", clip.filename);
|
||||
delete ctx;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !drwav_init(&ctx->wav, drwav_vfs_read, drwav_vfs_seek, drwav_vfs_tell, ctx, nullptr) ) {
|
||||
if ( !drwav_init(&ctx->wav, funs::read, funs::seek, funs::tell, ctx, nullptr) ) {
|
||||
UF_MSG_ERROR("Could not open WAV file: {}", clip.filename);
|
||||
delete ctx;
|
||||
return;
|
||||
@ -110,20 +160,19 @@ void ext::wav::load( pod::AudioClip& clip ) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!clip.streamed) {
|
||||
if ( !clip.streamed ) {
|
||||
uf::stl::vector<int16_t> pcm(wav->totalPCMFrameCount * wav->channels);
|
||||
drwav_read_pcm_frames_s16(wav, wav->totalPCMFrameCount, pcm.data());
|
||||
clip.alBuffer.buffer(clip.info.format, pcm.data(), (ALsizei)(pcm.size() * sizeof(int16_t)), clip.info.frequency);
|
||||
if ( clip.info.loop.has ) {
|
||||
ALint loopPoints[2] = { (ALint) clip.info.loop.start, (ALint) clip.info.loop.end };
|
||||
alBufferiv(clip.alBuffer.getIndex(0), 0x2015 /* AL_LOOP_POINTS_SOFT */, loopPoints);
|
||||
clip.alBuffer.set( 0x2015 /* AL_LOOP_POINTS_SOFT */, loopPoints );
|
||||
}
|
||||
}
|
||||
|
||||
drwav_uninit(wav);
|
||||
delete ctx;
|
||||
}
|
||||
|
||||
void ext::wav::open( pod::AudioSource& source ) {
|
||||
pod::AudioClip* clip = source.clip;
|
||||
if ( !clip || !clip->streamed ) return;
|
||||
@ -131,114 +180,76 @@ void ext::wav::open( pod::AudioSource& source ) {
|
||||
source.streamBuffers.initialize(source.settings.buffers);
|
||||
|
||||
DrWavVfsContext* ctx = new DrWavVfsContext();
|
||||
ctx->filename = clip->filename;
|
||||
ctx->currentOffset = 0;
|
||||
ctx->totalSize = uf::vfs::size(clip->filename);
|
||||
ctx->file = uf::vfs::open(clip->filename);
|
||||
if ( !ctx->file ) {
|
||||
UF_MSG_ERROR("WAV: failed to open file: {}", clip->filename);
|
||||
delete ctx;
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !drwav_init(&ctx->wav, drwav_vfs_read, drwav_vfs_seek, drwav_vfs_tell, ctx, nullptr) ) {
|
||||
if ( !drwav_init(&ctx->wav, funs::read, funs::seek, funs::tell, ctx, nullptr) ) {
|
||||
UF_MSG_ERROR("WAV: failed to open file: {}", clip->filename);
|
||||
delete ctx; return;
|
||||
}
|
||||
|
||||
source.streamState.handle = (void*) ctx;
|
||||
drwav* wav = &ctx->wav;
|
||||
|
||||
size_t frameSize = wav->channels * sizeof(uint16_t); // (wav->bitsPerSample / 8);
|
||||
size_t bufferFrames = uf::audio::bufferSize / frameSize;
|
||||
|
||||
int16_t buffer[uf::audio::bufferSize / 2];
|
||||
#if UF_USE_AICA
|
||||
source.streamBuffers.set( AL_STREAM_FILL_CALLBACK, (ALint*)(funs::fill_buffer) );
|
||||
source.streamBuffers.set( AL_STREAM_USER_DATA, (ALint*)(&source) );
|
||||
source.alSource.set(AL_BUFFER, (ALint)(source.streamBuffers.getIndex(0)));
|
||||
source.streamBuffers.buffer( clip->info.format, NULL, 0, clip->info.frequency );
|
||||
#else
|
||||
uint8_t buffer[uf::audio::bufferSize];
|
||||
uint8_t queuedBuffers = 0;
|
||||
|
||||
for ( ; queuedBuffers < source.settings.buffers; ++queuedBuffers ) {
|
||||
drwav_uint64 framesRead = drwav_read_pcm_frames_s16(wav, bufferFrames, buffer);
|
||||
int totalRead = funs::fill_buffer(&source, buffer, uf::audio::bufferSize);
|
||||
if ( totalRead == 0 ) break;
|
||||
|
||||
if ( framesRead == 0 ) {
|
||||
if ( source.settings.loop ) {
|
||||
drwav_seek_to_pcm_frame(wav, clip->info.loop.has ? clip->info.loop.start : 0);
|
||||
framesRead = drwav_read_pcm_frames_s16(wav, bufferFrames, buffer);
|
||||
}
|
||||
}
|
||||
if ( framesRead == 0 ) break;
|
||||
|
||||
AL_CHECK_RESULT(alBufferData(source.streamBuffers.getIndex(queuedBuffers), clip->info.format, buffer, (ALsizei)(framesRead * frameSize), clip->info.frequency));
|
||||
ext::al::Buffer::buffer( source.streamBuffers.getIndex(queuedBuffers), clip->info.format, buffer, totalRead, clip->info.frequency);
|
||||
}
|
||||
AL_CHECK_RESULT(alSourceQueueBuffers(source.alSource.getIndex(), queuedBuffers, &source.streamBuffers.getIndex(0)));
|
||||
source.alSource.queue( queuedBuffers, &source.streamBuffers.getIndex(0) );
|
||||
|
||||
if ( queuedBuffers >= source.settings.buffers ) {
|
||||
source.settings.loopMode = 1;
|
||||
source.alSource.set(AL_LOOPING, AL_FALSE);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ext::wav::update( pod::AudioSource& source ) {
|
||||
pod::AudioClip* clip = source.clip;
|
||||
if ( !clip || !clip->streamed || !source.streamState.handle ) return;
|
||||
|
||||
#if UF_USE_AICA
|
||||
ALint state;
|
||||
source.alSource.get(AL_SOURCE_STATE, state);
|
||||
if ( state == AL_PLAYING ) {
|
||||
source.streamBuffers.poll();
|
||||
}
|
||||
#else
|
||||
DrWavVfsContext* ctx = (DrWavVfsContext*) source.streamState.handle;
|
||||
drwav* wav = &ctx->wav;
|
||||
|
||||
ALint state, processed, queued;
|
||||
|
||||
source.alSource.get(AL_SOURCE_STATE, state);
|
||||
source.alSource.get(AL_BUFFERS_PROCESSED, processed);
|
||||
source.alSource.get(AL_BUFFERS_QUEUED, queued);
|
||||
|
||||
bool hasData = (ctx->currentOffset < ctx->totalSize) || !source.info.pending.empty() || source.settings.loop;
|
||||
#if 0 && !NO_FUN // if the engine cannot feed buffers, OpenAL will continue to loop the buffers
|
||||
source.alSource.set(AL_LOOPING, hasData ? AL_TRUE : AL_FALSE);
|
||||
#else // consume buffers automatically
|
||||
bool hasData = (ctx->file.tell(ctx->file.handle) < clip->info.size) || !source.info.pending.empty() || source.settings.loop;
|
||||
#if !NO_FUN
|
||||
if ( source.settings.loopMode == 1 ) {
|
||||
source.alSource.set(AL_LOOPING, AL_FALSE);
|
||||
source.settings.loopMode = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t frameSize = wav->channels * sizeof(uint16_t);
|
||||
size_t bufferFrames = uf::audio::bufferSize / frameSize;
|
||||
int16_t buffer[uf::audio::bufferSize / 2];
|
||||
|
||||
auto fillAndQueueBuffer = [&](ALuint index) -> bool {
|
||||
drwav_uint64 totalFramesRead = 0;
|
||||
int16_t* bufferPtr = buffer;
|
||||
uint8_t buffer[uf::audio::bufferSize];
|
||||
int totalRead = funs::fill_buffer(&source, buffer, uf::audio::bufferSize);
|
||||
|
||||
while ( totalFramesRead < bufferFrames ) {
|
||||
drwav_uint64 framesToRead = bufferFrames - totalFramesRead;
|
||||
drwav_uint64 framesRead = drwav_read_pcm_frames_s16(wav, framesToRead, bufferPtr);
|
||||
|
||||
totalFramesRead += framesRead;
|
||||
bufferPtr += (framesRead * wav->channels);
|
||||
|
||||
if ( framesRead == 0 ) {
|
||||
if ( !source.info.pending.empty() ) {
|
||||
uf::stl::string nextFile = source.info.pending.front();
|
||||
source.info.pending.erase(source.info.pending.begin());
|
||||
|
||||
drwav_uninit(wav);
|
||||
ctx->filename = uf::io::resolveURI(nextFile);
|
||||
ctx->currentOffset = 0;
|
||||
ctx->totalSize = uf::vfs::size(ctx->filename);
|
||||
|
||||
if ( !drwav_init(wav, drwav_vfs_read, drwav_vfs_seek, drwav_vfs_tell, ctx, nullptr) ) {
|
||||
UF_MSG_ERROR("Transition failed! Could not open: {}", ctx->filename);
|
||||
break;
|
||||
}
|
||||
|
||||
clip->filename = nextFile;
|
||||
clip->info.size = ctx->totalSize;
|
||||
clip->info.duration = (double)wav->totalPCMFrameCount / wav->sampleRate;
|
||||
|
||||
source.info.elapsed = 0.0f;
|
||||
source.info.timer.reset();
|
||||
source.info.timer.start();
|
||||
} else if ( source.settings.loop ) {
|
||||
drwav_seek_to_pcm_frame(wav, clip->info.loop.has ? clip->info.loop.start : 0);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ( totalFramesRead > 0 ) {
|
||||
AL_CHECK_RESULT(alBufferData(index, clip->info.format, buffer, (ALsizei)(totalFramesRead * frameSize), clip->info.frequency));
|
||||
AL_CHECK_RESULT(alSourceQueueBuffers(source.alSource.getIndex(), 1, &index));
|
||||
if ( totalRead > 0 ) {
|
||||
ext::al::Buffer::buffer(index, clip->info.format, buffer, totalRead, clip->info.frequency);
|
||||
source.alSource.queue( 1, &index );
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -253,16 +264,12 @@ void ext::wav::update( pod::AudioSource& source ) {
|
||||
} else {
|
||||
while ( processed > 0 ) {
|
||||
ALuint index;
|
||||
AL_CHECK_RESULT(alSourceUnqueueBuffers(source.alSource.getIndex(), 1, &index));
|
||||
source.alSource.unqueue( 1, &index );
|
||||
processed--;
|
||||
|
||||
bool hasData = (ctx->currentOffset < ctx->totalSize) || !source.info.pending.empty() || source.settings.loop;
|
||||
bool hasData = (ctx->file.tell(ctx->file.handle) < clip->info.size) || !source.info.pending.empty() || source.settings.loop;
|
||||
|
||||
if ( hasData ) {
|
||||
fillAndQueueBuffer(index);
|
||||
} else {
|
||||
// ensure AL_LOOPING is off
|
||||
}
|
||||
if ( hasData ) fillAndQueueBuffer(index);
|
||||
}
|
||||
}
|
||||
|
||||
@ -272,6 +279,11 @@ void ext::wav::update( pod::AudioSource& source ) {
|
||||
if ( state != AL_PLAYING && queued > 0 ) {
|
||||
source.alSource.play();
|
||||
}
|
||||
#if !NO_FUN
|
||||
if ( source.settings.loopMode == 1 ) source.alSource.set(AL_LOOPING, AL_FALSE);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void ext::wav::close( pod::AudioClip& clip ) {
|
||||
@ -284,8 +296,9 @@ void ext::wav::close(pod::AudioSource& source) {
|
||||
source.alSource.get(AL_BUFFERS_QUEUED, queued);
|
||||
while ( queued-- ) {
|
||||
ALuint buffer;
|
||||
alSourceUnqueueBuffers(source.alSource.getIndex(), 1, &buffer);
|
||||
source.alSource.unqueue( 1, &buffer );
|
||||
}
|
||||
|
||||
source.streamBuffers.destroy();
|
||||
|
||||
if ( source.streamState.handle ) {
|
||||
@ -296,4 +309,4 @@ void ext::wav::close(pod::AudioSource& source) {
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
#include <uf/config.h>
|
||||
|
||||
#if UF_USE_OPENAL
|
||||
#if UF_USE_OPENAL && !UF_USE_AICA
|
||||
#include <uf/ext/openal/openal.h>
|
||||
#include <uf/utils/memory/pool.h>
|
||||
#include <uf/utils/string/io.h>
|
||||
@ -46,6 +46,8 @@ void ext::al::initialize() {
|
||||
if ( hasEfx == AL_FALSE ) {
|
||||
UF_MSG_WARNING("AL_EXT_EFX not supported! Spatial audio will lack occlusion.");
|
||||
}
|
||||
|
||||
UF_MSG_DEBUG("AL initialized.");
|
||||
}
|
||||
void ext::al::destroy() {
|
||||
#if UF_USE_ALUT
|
||||
@ -76,7 +78,14 @@ uf::stl::string ext::al::getError( ALCenum error ) {
|
||||
}
|
||||
return FMT_FORMAT("AL_UNKNOWN({})", error);
|
||||
}
|
||||
|
||||
//
|
||||
void ext::al::Listener::set( ALenum name, ALfloat x, ALfloat y, ALfloat z ) {
|
||||
AL_CHECK_RESULT_ENUM(alListener3f, name, x, y, z);
|
||||
}
|
||||
void ext::al::Listener::set( ALenum name, const ALfloat* values ) {
|
||||
alListenerfv(name, values);
|
||||
}
|
||||
//
|
||||
void ext::al::Source::initialize() {
|
||||
if ( this->m_index ) this->destroy();
|
||||
AL_CHECK_RESULT(alGenSources(1, &this->m_index));
|
||||
@ -214,9 +223,19 @@ void ext::al::Source::set( const uf::stl::string& string, const ALint* f ) {
|
||||
UF_MSG_ERROR("AL error: Invalid enum requested: {}", string);
|
||||
}
|
||||
|
||||
void ext::al::Source::queue( ALsizei n, ALuint* indices ) {
|
||||
AL_CHECK_RESULT(alSourceQueueBuffers(this->m_index, n, indices));
|
||||
}
|
||||
void ext::al::Source::unqueue( ALsizei n, ALuint* indices ) {
|
||||
AL_CHECK_RESULT(alSourceUnqueueBuffers(this->m_index, n, indices));
|
||||
}
|
||||
|
||||
void ext::al::Source::play() {
|
||||
AL_CHECK_RESULT(alSourcePlay(this->m_index));
|
||||
}
|
||||
void ext::al::Source::pause() {
|
||||
AL_CHECK_RESULT(alSourcePause(this->m_index));
|
||||
}
|
||||
void ext::al::Source::stop() {
|
||||
AL_CHECK_RESULT(alSourceStop(this->m_index));
|
||||
}
|
||||
@ -242,10 +261,17 @@ void ext::al::Buffer::destroy() {
|
||||
ALuint& ext::al::Buffer::getIndex( size_t i ) { return this->m_indices[i]; }
|
||||
ALuint ext::al::Buffer::getIndex( size_t i ) const { return this->m_indices[i]; }
|
||||
|
||||
void ext::al::Buffer::set( ALenum name, ALint* iv, size_t i ) {
|
||||
AL_CHECK_RESULT(alBufferiv( this->m_indices[i], name, iv ));
|
||||
}
|
||||
void ext::al::Buffer::buffer(ALenum format, const ALvoid* data, ALsizei size, ALsizei frequency, size_t i ) {
|
||||
if ( !this->initialized() ) this->initialize();
|
||||
AL_CHECK_RESULT(alBufferData(this->m_indices[i], format, data, size, frequency));
|
||||
ext::al::Buffer::buffer( this->m_indices[i], format, data, size, frequency );
|
||||
}
|
||||
void ext::al::Buffer::buffer(ALuint index, ALenum format, const ALvoid* data, ALsizei size, ALsizei frequency ) {
|
||||
AL_CHECK_RESULT(alBufferData( index, format, data, size, frequency ));
|
||||
}
|
||||
|
||||
|
||||
#if UF_ENV_DREAMCAST
|
||||
void ext::al::Filter::initialize() {
|
||||
|
||||
@ -379,7 +379,7 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer::
|
||||
}
|
||||
|
||||
#if 0 && UF_ENV_DREAMCAST
|
||||
// washingtondc has a regression where non-alpha-tested polys do not render
|
||||
// washingtondc ~~has~~ had a regression where non-alpha-tested polys do not render
|
||||
// more convenient to just work around the regression since later builds have working opengl backends
|
||||
GL_ERROR_CHECK(glEnable(GL_ALPHA_TEST));
|
||||
GL_ERROR_CHECK(glAlphaFunc(GL_GREATER, drawInfo.blend.alphaCutoff));
|
||||
@ -450,6 +450,7 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer::
|
||||
pod::Vector4f color = {1,1,1,1};
|
||||
if ( drawInfo.color.enabled ) {
|
||||
color = drawInfo.color.pointer ? *drawInfo.color.pointer : drawInfo.color.value;
|
||||
color = uf::vector::clamp( color, pod::Vector4f{0,0,0,0}, pod::Vector4f{1, 1, 1, 1} );
|
||||
}
|
||||
if ( color != ::shadowState.color ) {
|
||||
GL_ERROR_CHECK(glColor4f( color[0], color[1], color[2], color[3] ));
|
||||
@ -598,6 +599,8 @@ void ext::opengl::CommandBuffer::drawIndexed( const ext::opengl::CommandBuffer::
|
||||
|
||||
GL_ERROR_CHECK(glTexCoordPointer(2, uvType, uvStride, uvPtr));
|
||||
GL_ERROR_CHECK(glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, drawInfo.attributes.color.pointer ? GL_MODULATE : GL_REPLACE));
|
||||
// washdc works fine, flycast renders nothing if GL_MODULATE is set, although GL_REPLACE just renders the background
|
||||
//GL_ERROR_CHECK(glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE));
|
||||
} else {
|
||||
if ( ::shadowState.tex0Enabled ) {
|
||||
GL_ERROR_CHECK(glClientActiveTexture(GL_TEXTURE0));
|
||||
|
||||
@ -63,12 +63,7 @@ void ext::opengl::Texture::updateDescriptors() {
|
||||
descriptor.layers = layers;
|
||||
}
|
||||
bool ext::opengl::Texture::generated() const {
|
||||
#if UF_ENV_DREAMCAST
|
||||
return image != GL_NULL_HANDLE;
|
||||
#else
|
||||
return image != GL_NULL_HANDLE;
|
||||
// return glIsTexture(image);
|
||||
#endif
|
||||
}
|
||||
void ext::opengl::Texture::destroy( bool defer ) {
|
||||
// if ( !device ) return;
|
||||
@ -107,8 +102,71 @@ void ext::opengl::Texture::loadFromImage(
|
||||
Device& device,
|
||||
enums::Format::type_t format
|
||||
) {
|
||||
format = image.getFormat( srgb );
|
||||
internalFormat = image.format > 0 ? format : 0;
|
||||
switch ( format ) {
|
||||
case enums::Format::R8_SRGB:
|
||||
case enums::Format::R8G8_SRGB:
|
||||
case enums::Format::R8G8B8_SRGB:
|
||||
case enums::Format::R8G8B8A8_SRGB:
|
||||
srgb = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if ( image.getFormat() != 0 ) {
|
||||
internalFormat = image.getFormat();
|
||||
} else {
|
||||
switch ( image.getChannels() ) {
|
||||
// R
|
||||
case 1:
|
||||
switch ( image.getBpp() ) {
|
||||
case 8:
|
||||
format = srgb ? enums::Format::R8_SRGB : enums::Format::R8_UNORM;
|
||||
break;
|
||||
default:
|
||||
UF_EXCEPTION("OpenGL error: unsupported BPP of {}", image.getBpp() );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
// RB
|
||||
case 2:
|
||||
switch ( image.getBpp() ) {
|
||||
case 16:
|
||||
format = srgb ? enums::Format::R8G8_SRGB : enums::Format::R8G8_UNORM;
|
||||
break;
|
||||
default:
|
||||
UF_EXCEPTION("OpenGL error: unsupported BPP of {}", image.getBpp() );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
// RGB
|
||||
case 3:
|
||||
switch ( image.getBpp() ) {
|
||||
case 24:
|
||||
format = srgb ? enums::Format::R8G8B8_SRGB : enums::Format::R8G8B8_UNORM;
|
||||
break;
|
||||
default:
|
||||
UF_EXCEPTION("OpenGL error: unsupported BPP of {}", image.getBpp() );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
// RGBA
|
||||
case 4:
|
||||
switch ( image.getBpp() ) {
|
||||
case 16:
|
||||
format = enums::Format::R4G4B4A4_UNORM_PACK16;
|
||||
break;
|
||||
case 32:
|
||||
format = srgb ? enums::Format::R8G8B8A8_SRGB : enums::Format::R8G8B8A8_UNORM;
|
||||
break;
|
||||
default:
|
||||
UF_EXCEPTION("OpenGL error: unsupported BPP of {}", image.getBpp() );
|
||||
break;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
UF_EXCEPTION("OpenGL error: unsupported channels of {}", image.getChannels() );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
this->fromBuffers(
|
||||
(void*) image.getPixelsPtr(),
|
||||
|
||||
108
engine/src/ext/truetype/truetype.cpp
Normal file
108
engine/src/ext/truetype/truetype.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
#if UF_USE_TRUETYPE
|
||||
#include <uf/ext/truetype/truetype.h>
|
||||
#include <uf/utils/io/file.h>
|
||||
#include <uf/utils/memory/unordered_map.h>
|
||||
|
||||
#define STB_TRUETYPE_IMPLEMENTATION
|
||||
#include <stb_truetype.h>
|
||||
|
||||
namespace impl {
|
||||
uf::stl::unordered_map<uf::stl::string, uf::stl::vector<uint8_t>> fontCache;
|
||||
|
||||
uint64_t first_codepoint(const std::u8string& str) {
|
||||
if ( str.empty() ) UF_EXCEPTION("Empty string");
|
||||
|
||||
const uint8_t* bytes = reinterpret_cast<const uint8_t*>(str.data());
|
||||
uint8_t b0 = bytes[0];
|
||||
uint64_t codepoint = 0;
|
||||
int extra_bytes = 0;
|
||||
|
||||
if (b0 < 0x80) {
|
||||
return b0;
|
||||
} else if ((b0 >> 5) == 0x6) {
|
||||
codepoint = b0 & 0x1F;
|
||||
extra_bytes = 1;
|
||||
} else if ((b0 >> 4) == 0xE) {
|
||||
codepoint = b0 & 0x0F;
|
||||
extra_bytes = 2;
|
||||
} else if ((b0 >> 3) == 0x1E) {
|
||||
codepoint = b0 & 0x07;
|
||||
extra_bytes = 3;
|
||||
} else {
|
||||
UF_EXCEPTION("Invalid UTF-8 start byte");
|
||||
}
|
||||
|
||||
for (int i = 0; i < extra_bytes; ++i) {
|
||||
uint8_t bx = bytes[i+1];
|
||||
if ((bx >> 6) != 0x2) UF_EXCEPTION("Invalid continuation byte");
|
||||
codepoint = (codepoint << 6) | (bx & 0x3F);
|
||||
}
|
||||
|
||||
return codepoint;
|
||||
}
|
||||
}
|
||||
|
||||
pod::TrueTypeFont::TrueTypeFont() : info(nullptr) {}
|
||||
|
||||
pod::TrueTypeFont::~TrueTypeFont() {
|
||||
ext::truetype::destroy( *this );
|
||||
}
|
||||
|
||||
bool ext::truetype::initialize() {
|
||||
return true;
|
||||
}
|
||||
|
||||
void ext::truetype::terminate() {
|
||||
impl::fontCache.clear();
|
||||
}
|
||||
|
||||
bool ext::truetype::initialize( pod::TrueTypeFont& g, const uf::stl::string& filename ) {
|
||||
if ( impl::fontCache.find(filename) == impl::fontCache.end() ) {
|
||||
uf::stl::vector<uint8_t> buffer;
|
||||
if ( !uf::io::readAsBuffer( buffer, filename ) ) {
|
||||
UF_MSG_ERROR("stb_truetype failed to read file: {}", filename);
|
||||
return false;
|
||||
}
|
||||
impl::fontCache[filename] = std::move(buffer);
|
||||
}
|
||||
|
||||
const auto& buffer = impl::fontCache[filename];
|
||||
|
||||
g.info = new stbtt_fontinfo();
|
||||
stbtt_fontinfo* info = static_cast<stbtt_fontinfo*>(g.info);
|
||||
|
||||
if ( !stbtt_InitFont(info, buffer.data(), stbtt_GetFontOffsetForIndex(buffer.data(), 0)) ) {
|
||||
UF_MSG_ERROR("stb_truetype failed to initialize font memory '{}'", filename);
|
||||
delete info;
|
||||
g.info = nullptr;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ext::truetype::destroy( pod::TrueTypeFont& g ) {
|
||||
if ( g.info ) {
|
||||
delete static_cast<stbtt_fontinfo*>(g.info);
|
||||
g.info = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void ext::truetype::setPixelSizes( pod::TrueTypeFont& g, size_t height ) {
|
||||
if ( !g.info ) return;
|
||||
g.scale = stbtt_ScaleForPixelHeight(static_cast<stbtt_fontinfo*>(g.info), static_cast<float>(height));
|
||||
}
|
||||
|
||||
bool ext::truetype::load( pod::TrueTypeFont& g, uint64_t c ) {
|
||||
g.current_codepoint = c;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool ext::truetype::load( pod::TrueTypeFont& g, const uf::stl::string& string ) {
|
||||
#if UF_USE_DEPRECATED_STRING
|
||||
uint64_t c = string.translate<uf::locale::Utf32>().at(0);
|
||||
#else
|
||||
uint64_t c = impl::first_codepoint( std::u8string( string.begin(), string.end() ) );
|
||||
#endif
|
||||
return ext::truetype::load( g, c );
|
||||
}
|
||||
#endif
|
||||
@ -138,6 +138,119 @@ namespace {
|
||||
|
||||
return results;
|
||||
};
|
||||
|
||||
struct VpkFileStreamContext {
|
||||
size_t preloadBytes = 0;
|
||||
size_t entryLength = 0;
|
||||
const uint8_t* preloadData = nullptr;
|
||||
|
||||
FILE* chunkHandle = nullptr;
|
||||
size_t chunkBaseOffset = 0;
|
||||
|
||||
size_t cursor = 0;
|
||||
};
|
||||
|
||||
size_t vpk_file_read(void* handle, void* buffer, size_t bytes) {
|
||||
VpkFileStreamContext* ctx = (VpkFileStreamContext*)handle;
|
||||
size_t totalSize = ctx->preloadBytes + ctx->entryLength;
|
||||
|
||||
if (ctx->cursor >= totalSize) return 0;
|
||||
|
||||
size_t bytesToRead = std::min(bytes, totalSize - ctx->cursor);
|
||||
size_t bytesRead = 0;
|
||||
uint8_t* out = (uint8_t*)buffer;
|
||||
|
||||
if (ctx->cursor < ctx->preloadBytes) {
|
||||
size_t preloadRead = std::min(bytesToRead, ctx->preloadBytes - ctx->cursor);
|
||||
std::memcpy(out, ctx->preloadData + ctx->cursor, preloadRead);
|
||||
|
||||
ctx->cursor += preloadRead;
|
||||
out += preloadRead;
|
||||
bytesRead += preloadRead;
|
||||
bytesToRead -= preloadRead;
|
||||
}
|
||||
|
||||
if (bytesToRead > 0 && ctx->chunkHandle) {
|
||||
size_t physicalOffset = ctx->chunkBaseOffset + (ctx->cursor - ctx->preloadBytes);
|
||||
fseek(ctx->chunkHandle, physicalOffset, SEEK_SET);
|
||||
|
||||
size_t chunkRead = fread(out, 1, bytesToRead, ctx->chunkHandle);
|
||||
ctx->cursor += chunkRead;
|
||||
bytesRead += chunkRead;
|
||||
}
|
||||
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
bool vpk_file_seek(void* handle, long offset, int origin) {
|
||||
VpkFileStreamContext* ctx = (VpkFileStreamContext*)handle;
|
||||
long newCursor = ctx->cursor;
|
||||
long totalSize = ctx->preloadBytes + ctx->entryLength;
|
||||
|
||||
if (origin == SEEK_SET) newCursor = offset;
|
||||
else if (origin == SEEK_CUR) newCursor += offset;
|
||||
else if (origin == SEEK_END) newCursor = totalSize + offset;
|
||||
|
||||
if (newCursor < 0) newCursor = 0;
|
||||
if (newCursor > totalSize) newCursor = totalSize;
|
||||
|
||||
ctx->cursor = newCursor;
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t vpk_file_tell(void* handle) {
|
||||
return ((VpkFileStreamContext*)handle)->cursor;
|
||||
}
|
||||
|
||||
void vpk_file_close(void* handle) {
|
||||
VpkFileStreamContext* ctx = (VpkFileStreamContext*)handle;
|
||||
if (ctx->chunkHandle) fclose(ctx->chunkHandle);
|
||||
delete ctx;
|
||||
}
|
||||
|
||||
pod::File open(pod::Mount& mount, const uf::stl::string& path) {
|
||||
auto& state = uf::pointeredUserdata::get<VpkMountState>( mount.userdata );
|
||||
auto archive = state.get();
|
||||
if ( !archive ) return pod::File{};
|
||||
|
||||
auto it = archive->files.find( uf::string::lowercase(path) );
|
||||
if ( it == archive->files.end() ) return pod::File{};
|
||||
|
||||
const auto& entry = it->second;
|
||||
|
||||
VpkFileStreamContext* ctx = new VpkFileStreamContext();
|
||||
ctx->preloadBytes = entry.metadata.preloadBytes;
|
||||
ctx->entryLength = entry.metadata.entryLength;
|
||||
ctx->preloadData = entry.metadata.preloadBytes > 0 ? entry.preloadData.data() : nullptr;
|
||||
ctx->cursor = 0;
|
||||
|
||||
if ( ctx->entryLength > 0 ) {
|
||||
uf::stl::string archivePath;
|
||||
|
||||
if ( entry.metadata.archiveIndex == 0x7FFF ) {
|
||||
archivePath = archive->basePath + "_dir.vpk";
|
||||
ctx->chunkBaseOffset = entry.dirFileOffset + entry.metadata.entryOffset;
|
||||
} else {
|
||||
archivePath = FMT_FORMAT("{}_{:03d}.vpk", archive->basePath, entry.metadata.archiveIndex);
|
||||
ctx->chunkBaseOffset = entry.metadata.entryOffset;
|
||||
}
|
||||
|
||||
ctx->chunkHandle = fopen(archivePath.c_str(), "rb");
|
||||
if ( !ctx->chunkHandle ) {
|
||||
UF_MSG_ERROR("Failed to open VPK chunk for streaming: {}", archivePath);
|
||||
delete ctx;
|
||||
return pod::File{};
|
||||
}
|
||||
}
|
||||
|
||||
return pod::File{
|
||||
.handle = ctx,
|
||||
.read = vpk_file_read,
|
||||
.seek = vpk_file_seek,
|
||||
.tell = vpk_file_tell,
|
||||
.close = vpk_file_close
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pod::Mount ext::valve::createVpkMount( const uf::stl::string& uri, int priority ) {
|
||||
@ -153,6 +266,7 @@ pod::Mount ext::valve::createVpkMount( const uf::stl::string& uri, int priority
|
||||
mount.exists = ::exists;
|
||||
mount.size = ::size;
|
||||
mount.list = ::list;
|
||||
mount.open = ::open;
|
||||
mount.mtime = ::mtime;
|
||||
mount.read = ::read;
|
||||
mount.readRange = ::readRange;
|
||||
|
||||
@ -326,6 +326,49 @@ namespace {
|
||||
uf::stl::unordered_map<uf::stl::string, pod::ZipEntry> entries;
|
||||
};
|
||||
|
||||
struct ZipFileStream {
|
||||
const uint8_t* data = nullptr;
|
||||
size_t size = 0;
|
||||
size_t cursor = 0;
|
||||
uf::stl::vector<uint8_t> decompressedBuffer;
|
||||
};
|
||||
|
||||
size_t zip_file_read(void* handle, void* buffer, size_t bytes) {
|
||||
ZipFileStream* stream = (ZipFileStream*)handle;
|
||||
size_t bytesLeft = stream->size - stream->cursor;
|
||||
size_t toRead = (bytes > bytesLeft) ? bytesLeft : bytes;
|
||||
|
||||
if (toRead > 0) {
|
||||
std::memcpy(buffer, stream->data + stream->cursor, toRead);
|
||||
stream->cursor += toRead;
|
||||
}
|
||||
return toRead;
|
||||
}
|
||||
|
||||
bool zip_file_seek(void* handle, long offset, int origin) {
|
||||
ZipFileStream* stream = (ZipFileStream*)handle;
|
||||
long target = 0;
|
||||
|
||||
if (origin == SEEK_SET) target = offset;
|
||||
else if (origin == SEEK_CUR) target = (long)stream->cursor + offset;
|
||||
else if (origin == SEEK_END) target = (long)stream->size + offset;
|
||||
|
||||
if (target < 0) target = 0;
|
||||
if ((size_t)target > stream->size) target = stream->size;
|
||||
|
||||
stream->cursor = (size_t)target;
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t zip_file_tell(void* handle) {
|
||||
return ((ZipFileStream*)handle)->cursor;
|
||||
}
|
||||
|
||||
void zip_file_close(void* handle) {
|
||||
ZipFileStream* stream = (ZipFileStream*)handle;
|
||||
delete stream;
|
||||
}
|
||||
|
||||
bool vfs_exists( pod::Mount& mount, const uf::stl::string& file ){
|
||||
auto& state = uf::pointeredUserdata::get<ZipMountState>( mount.userdata );
|
||||
return state.entries.find(file) != state.entries.end();
|
||||
@ -372,6 +415,42 @@ namespace {
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
pod::File vfs_open(pod::Mount& mount, const uf::stl::string& file) {
|
||||
auto& state = uf::pointeredUserdata::get<ZipMountState>(mount.userdata);
|
||||
auto it = state.entries.find(file);
|
||||
if (it == state.entries.end()) return pod::File{};
|
||||
|
||||
const auto& entry = it->second;
|
||||
const uint8_t* fileData = state.buffer.data() + entry.offset;
|
||||
|
||||
ZipFileStream* stream = new ZipFileStream();
|
||||
stream->size = entry.uncompressedSize;
|
||||
stream->cursor = 0;
|
||||
|
||||
if (entry.compressionMethod == 0) {
|
||||
stream->data = fileData;
|
||||
}
|
||||
else if (entry.compressionMethod == 8) {
|
||||
if (!ext::zlib::decompressFromMemory(stream->decompressedBuffer, fileData, entry.compressedSize, entry.uncompressedSize, -15)) {
|
||||
delete stream;
|
||||
return pod::File{};
|
||||
}
|
||||
stream->data = stream->decompressedBuffer.data();
|
||||
}
|
||||
else {
|
||||
delete stream;
|
||||
return pod::File{};
|
||||
}
|
||||
|
||||
return pod::File{
|
||||
.handle = stream,
|
||||
.read = zip_file_read,
|
||||
.seek = zip_file_seek,
|
||||
.tell = zip_file_tell,
|
||||
.close = zip_file_close
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
pod::Mount ext::zlib::createZipMount( const uf::stl::string& uri, uf::stl::vector<uint8_t>& buffer, int priority ) {
|
||||
@ -392,6 +471,7 @@ pod::Mount ext::zlib::createZipMount( const uf::stl::string& uri, uf::stl::vecto
|
||||
mount.size = ::vfs_size;
|
||||
mount.read = ::vfs_read;
|
||||
mount.list = ::vfs_list;
|
||||
mount.open = ::vfs_open;
|
||||
|
||||
auto& state = uf::pointeredUserdata::get<ZipMountState>( mount.userdata );
|
||||
state.buffer = buffer;
|
||||
|
||||
@ -11,11 +11,7 @@
|
||||
#include <uf/ext/audio/wav.h>
|
||||
#include <uf/ext/audio/pcm.h>
|
||||
|
||||
#if UF_USE_OPENAL
|
||||
bool uf::audio::muted = false;
|
||||
#else
|
||||
bool uf::audio::muted = true;
|
||||
#endif
|
||||
bool uf::audio::muted = false;
|
||||
|
||||
namespace {
|
||||
ext::al::Filter occlusionFilter;
|
||||
@ -43,18 +39,22 @@ void uf::audio::initialize( pod::AudioSource& source ) {
|
||||
source.alSource.set( AL_PITCH, 1.0f );
|
||||
source.alSource.set( AL_GAIN, 1.0f );
|
||||
|
||||
#if UF_USE_AICA
|
||||
source.settings.buffers = 1;
|
||||
#endif
|
||||
#if !UF_ENV_DREAMCAST
|
||||
source.alFilter.initialize();
|
||||
#endif
|
||||
}
|
||||
|
||||
bool uf::audio::load( pod::AudioClip& clip, const uf::stl::string& filename, bool streamed ) {
|
||||
bool uf::audio::load( pod::AudioClip& clip, const uf::stl::string& filename ) {
|
||||
if ( uf::audio::muted ) return false;
|
||||
|
||||
uf::audio::destroy( clip );
|
||||
clip.streamed = streamed;
|
||||
clip.filename = uf::io::resolveURI( filename );
|
||||
clip.extension = uf::io::extension( clip.filename );
|
||||
|
||||
uf::audio::initialize( clip, 1 );
|
||||
if ( !clip.streamed ) uf::audio::initialize( clip, 1 );
|
||||
|
||||
if ( clip.extension == "ogg" ) ext::vorbis::load( clip );
|
||||
else if ( clip.extension == "wav" ) ext::wav::load( clip );
|
||||
@ -79,7 +79,7 @@ void uf::audio::bind( pod::AudioSource& source, pod::AudioClip* clip ) {
|
||||
source.streamState.consumed = 0;
|
||||
if ( clip->extension == "ogg" ) ext::vorbis::open( source );
|
||||
else if ( clip->extension == "wav" ) ext::wav::open( source );
|
||||
else if ( clip->extension == "pcm" ) ext::pcm::open( source );
|
||||
//else if ( clip->extension == "pcm" ) ext::pcm::open( source );
|
||||
}
|
||||
}
|
||||
|
||||
@ -104,13 +104,13 @@ void uf::audio::stop( pod::AudioSource& source ) {
|
||||
}
|
||||
|
||||
void uf::audio::pause( pod::AudioSource& source ) {
|
||||
AL_CHECK_RESULT(alSourcePause( source.alSource.getIndex() ));
|
||||
source.alSource.pause();
|
||||
source.info.timer.stop();
|
||||
}
|
||||
|
||||
bool uf::audio::paused( const pod::AudioSource& source ) {
|
||||
ALint state;
|
||||
AL_CHECK_RESULT(alGetSourcei( source.alSource.getIndex(), AL_SOURCE_STATE, &state ));
|
||||
int state;
|
||||
source.alSource.get( AL_SOURCE_STATE, state );
|
||||
return state == AL_PAUSED;
|
||||
}
|
||||
|
||||
@ -120,7 +120,7 @@ void uf::audio::update( pod::AudioSource& source ) {
|
||||
auto update = [&]{
|
||||
if ( source.clip->extension == "ogg" ) ext::vorbis::update( source );
|
||||
else if ( source.clip->extension == "wav" ) ext::wav::update( source );
|
||||
else if ( source.clip->extension == "pcm" ) ext::pcm::update( source );
|
||||
//else if ( source.clip->extension == "pcm" ) ext::pcm::update( source );
|
||||
};
|
||||
|
||||
if ( uf::audio::asyncUpdate ) uf::thread::queue( uf::thread::fetchWorker(), update );
|
||||
@ -142,7 +142,7 @@ void uf::audio::destroy( pod::AudioSource& source ) {
|
||||
if ( source.clip && source.clip->streamed ) {
|
||||
if ( source.clip->extension == "ogg" ) ext::vorbis::close( source );
|
||||
else if ( source.clip->extension == "wav" ) ext::wav::close( source );
|
||||
else if ( source.clip->extension == "pcm" ) ext::pcm::close( source );
|
||||
//else if ( source.clip->extension == "pcm" ) ext::pcm::close( source );
|
||||
}
|
||||
|
||||
source.clip = nullptr;
|
||||
@ -156,7 +156,7 @@ void uf::audio::destroy( pod::AudioClip& clip ) {
|
||||
clip.alBuffer.destroy();
|
||||
if ( clip.extension == "ogg" ) ext::vorbis::close( clip );
|
||||
else if ( clip.extension == "wav" ) ext::wav::close( clip );
|
||||
else if ( clip.extension == "pcm" ) ext::pcm::close( clip );
|
||||
//else if ( clip.extension == "pcm" ) ext::pcm::close( clip );
|
||||
}
|
||||
|
||||
void uf::audio::listener( const pod::Transform<>& transform ) {
|
||||
@ -165,9 +165,10 @@ void uf::audio::listener( const pod::Transform<>& transform ) {
|
||||
auto axes = uf::transform::axes( transform );
|
||||
axes.forward *= -1;
|
||||
float o[6] = { axes.forward.x, axes.forward.y, axes.forward.z, axes.up.x, axes.up.y, axes.up.z };
|
||||
AL_CHECK_RESULT(alListener3f( AL_POSITION, transform.position.x, transform.position.y, transform.position.z ));
|
||||
AL_CHECK_RESULT(alListener3f( AL_VELOCITY, 0, 0, 0 ));
|
||||
AL_CHECK_RESULT(alListenerfv( AL_ORIENTATION, &o[0] ));
|
||||
|
||||
ext::al::Listener::set( AL_POSITION, transform.position.x, transform.position.y, transform.position.z );
|
||||
ext::al::Listener::set( AL_VELOCITY, 0.0f, 0.0f, 0.0f );
|
||||
ext::al::Listener::set( AL_ORIENTATION, &o[0] );
|
||||
}
|
||||
|
||||
void uf::audio::loop( pod::AudioSource& source, bool state ) {
|
||||
|
||||
@ -67,8 +67,8 @@ void uf::AudioEmitter::update() {
|
||||
|
||||
void uf::AudioEmitter::update( const pod::Vector3f& position, const pod::Quaternion<>& orientation ) {
|
||||
bool spatial = false;
|
||||
for ( auto& pair : this->m_container ) {
|
||||
for ( auto& source : pair.second ) {
|
||||
for ( auto& [ name, sources ] : this->m_container ) {
|
||||
for ( auto& source : sources ) {
|
||||
if ( source.alSource.playing() && source.settings.spatial ) {
|
||||
spatial = true;
|
||||
break;
|
||||
@ -87,8 +87,8 @@ void uf::AudioEmitter::update( const pod::Vector3f& position, const pod::Quatern
|
||||
}
|
||||
}
|
||||
|
||||
for ( auto& pair : this->m_container ) {
|
||||
for ( auto& source : pair.second ) {
|
||||
for ( auto& [ name, sources ] : this->m_container ) {
|
||||
for ( auto& source : sources ) {
|
||||
bool isPlaying = source.alSource.playing();
|
||||
bool hasPending = !source.info.pending.empty();
|
||||
|
||||
@ -103,11 +103,11 @@ void uf::AudioEmitter::update( const pod::Vector3f& position, const pod::Quatern
|
||||
uf::audio::occlude( source, occlusionValue );
|
||||
|
||||
if ( m_efxInitialized ) {
|
||||
AL_CHECK_RESULT(alSource3i( source.alSource.getIndex(), AL_AUXILIARY_SEND_FILTER, (ALint)m_effectSlot.getIndex(), 0, AL_FILTER_NULL ));
|
||||
source.alSource.set( AL_AUXILIARY_SEND_FILTER, (ALint)m_effectSlot.getIndex(), 0, AL_FILTER_NULL );
|
||||
}
|
||||
} else {
|
||||
if ( m_efxInitialized ) {
|
||||
AL_CHECK_RESULT(alSource3i( source.alSource.getIndex(), AL_AUXILIARY_SEND_FILTER, 0, 0, AL_FILTER_NULL ));
|
||||
source.alSource.set( AL_AUXILIARY_SEND_FILTER, 0, 0, AL_FILTER_NULL );
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,7 +157,7 @@ void uf::AudioEmitter::cleanup( bool purge ) {
|
||||
auto& source = *vecIt;
|
||||
|
||||
ALint state;
|
||||
alGetSourcei( source.alSource.getIndex(), AL_SOURCE_STATE, &state );
|
||||
source.alSource.get( AL_SOURCE_STATE, state );
|
||||
bool active = (state == AL_PLAYING || state == AL_PAUSED);
|
||||
|
||||
if ( purge || (!active && !source.settings.loop) ) {
|
||||
|
||||
@ -3,9 +3,19 @@
|
||||
#include <uf/utils/string/hash.h>
|
||||
#include <uf/utils/io/iostream.h>
|
||||
#include <uf/utils/io/vfs.h>
|
||||
#include <fstream> // std::fstream
|
||||
#include <iostream> // std::fstream
|
||||
#include <png/png.h> // libpng
|
||||
#include <fstream>
|
||||
|
||||
#if UF_ENV_DREAMCAST
|
||||
|
||||
#define STBI_NO_JPEG
|
||||
#define STBI_NO_BMP
|
||||
#define STBI_NO_PSD
|
||||
#define STBI_NO_GIF
|
||||
#define STBI_NO_PIC
|
||||
#define STBI_NO_PNM
|
||||
#define STBI_NO_HDR
|
||||
|
||||
#endif
|
||||
|
||||
#define STB_IMAGE_IMPLEMENTATION
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
@ -194,7 +204,18 @@ bool uf::image::open( pod::Image& image, const uf::stl::vector<uint8_t>& buffer,
|
||||
default: UF_EXCEPTION("Image error: invalid texture format"); return false;
|
||||
}
|
||||
}
|
||||
} else { UF_EXCEPTION("Image error: not a compressed texture"); return false; }
|
||||
} else {
|
||||
if ( twiddled ) {
|
||||
switch ( format ) {
|
||||
case 1: image.format = GL_RGB565_TWID_KOS; channels = 3; break;
|
||||
case 0: image.format = GL_ARGB1555_TWID_KOS; break;
|
||||
case 2: image.format = GL_ARGB4444_TWID_KOS ; break;
|
||||
default: UF_EXCEPTION("Image error: invalid texture format"); return false;
|
||||
}
|
||||
} else {
|
||||
UF_EXCEPTION("Unsupported configuration: compressed={}, twiddled={}, format={}", compressed, twiddled, format);
|
||||
}
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
@ -571,6 +592,8 @@ size_t uf::Image::getChannels() const {
|
||||
return this->channels;
|
||||
}
|
||||
size_t uf::Image::getFormat( bool srgb ) const {
|
||||
return this->format;
|
||||
/*
|
||||
auto format = this->format;
|
||||
|
||||
// for some reason i'm auto-deducing it here
|
||||
@ -629,6 +652,7 @@ size_t uf::Image::getFormat( bool srgb ) const {
|
||||
}
|
||||
|
||||
return format;
|
||||
*/
|
||||
}
|
||||
void uf::Image::setFormat( size_t format ) {
|
||||
this->format = format;
|
||||
|
||||
@ -381,7 +381,7 @@ uf::stl::string uf::io::preferred( const uf::stl::string& filename ) {
|
||||
// to-do: make this config.json defineable
|
||||
#if UF_ENV_DREAMCAST
|
||||
if ( assetType == "texture" ) preferredExtension = ".dtex";
|
||||
else if ( assetType == "audio" ) preferredExtension = ".ogg";
|
||||
else if ( assetType == "audio" ) preferredExtension = ".wav";
|
||||
#else
|
||||
if ( assetType == "texture" ) preferredExtension = ".png";
|
||||
else if ( assetType == "audio" ) preferredExtension = ".ogg";
|
||||
|
||||
@ -15,9 +15,11 @@ void uf::io::exception( const uf::stl::string& exception ) {
|
||||
*/
|
||||
uf::stl::string uf::io::log( const uf::stl::string& category, const uf::stl::string& file, const uf::stl::string& function, size_t line, const uf::stl::string& message ) {
|
||||
auto string = FMT_FORMAT("[{}] [{}:{}@{}]: {}", category, file, function, line, message);
|
||||
::fmt::print("{}\n", string);
|
||||
uf::iostream.pushHistory(string);
|
||||
#if 1 || !UF_ENV_DREAMCAST
|
||||
::fmt::print("{}\n", string);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
uf::console::print( string );
|
||||
|
||||
|
||||
@ -184,6 +184,85 @@ namespace {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//
|
||||
size_t disk_file_read(void* handle, void* buffer, size_t bytes) {
|
||||
return fread(buffer, 1, bytes, (FILE*)handle);
|
||||
}
|
||||
bool disk_file_seek(void* handle, long offset, int origin) {
|
||||
return fseek((FILE*)handle, offset, origin) == 0;
|
||||
}
|
||||
size_t disk_file_tell(void* handle) {
|
||||
return ftell((FILE*)handle);
|
||||
}
|
||||
void disk_file_close(void* handle) {
|
||||
if (handle) fclose((FILE*)handle);
|
||||
}
|
||||
|
||||
pod::File vfs_open( pod::Mount& mount, const uf::stl::string& file ) {
|
||||
uf::stl::string path = mount.path + file;
|
||||
FILE* f = fopen(path.c_str(), "rb");
|
||||
if ( !f ) return pod::File{};
|
||||
|
||||
return pod::File{
|
||||
.handle = f,
|
||||
.read = disk_file_read,
|
||||
.seek = disk_file_seek,
|
||||
.tell = disk_file_tell,
|
||||
.close = disk_file_close
|
||||
};
|
||||
}
|
||||
|
||||
// what a mess
|
||||
struct FallbackFileState {
|
||||
pod::Mount* mount;
|
||||
uf::stl::string relativePath;
|
||||
size_t offset;
|
||||
size_t totalSize;
|
||||
};
|
||||
|
||||
size_t fallback_file_read(void* handle, void* buffer, size_t bytes) {
|
||||
auto* state = (FallbackFileState*)(handle);
|
||||
if (!state || !state->mount || !state->mount->readRange) return 0;
|
||||
|
||||
size_t bytesLeft = state->totalSize - state->offset;
|
||||
size_t toRead = std::min(bytes, bytesLeft);
|
||||
if (toRead == 0) return 0;
|
||||
|
||||
uf::stl::vector<uint8_t> tempBuffer;
|
||||
if (state->mount->readRange(*state->mount, state->relativePath, state->offset, toRead, tempBuffer)) {
|
||||
std::memcpy(buffer, tempBuffer.data(), tempBuffer.size());
|
||||
state->offset += tempBuffer.size();
|
||||
return tempBuffer.size();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool fallback_file_seek(void* handle, long offset, int origin) {
|
||||
auto* state = (FallbackFileState*)(handle);
|
||||
if (!state) return false;
|
||||
|
||||
long long targetOffset = 0;
|
||||
if (origin == SEEK_SET) targetOffset = offset;
|
||||
else if (origin == SEEK_CUR) targetOffset = (long long)state->offset + offset;
|
||||
else if (origin == SEEK_END) targetOffset = (long long)state->totalSize + offset;
|
||||
|
||||
if (targetOffset < 0) targetOffset = 0;
|
||||
if (targetOffset > (long long)state->totalSize) targetOffset = state->totalSize;
|
||||
|
||||
state->offset = (size_t)targetOffset;
|
||||
return true;
|
||||
}
|
||||
|
||||
size_t fallback_file_tell(void* handle) {
|
||||
auto* state = (FallbackFileState*)(handle);
|
||||
return state ? state->offset : 0;
|
||||
}
|
||||
|
||||
void fallback_file_close(void* handle) {
|
||||
auto* state = (FallbackFileState*)(handle);
|
||||
if (state) delete state;
|
||||
}
|
||||
}
|
||||
|
||||
uf::vfs::Mount::~Mount() {
|
||||
@ -206,10 +285,11 @@ pod::Mount uf::vfs::createDiskMount( const uf::stl::string& uri, int priority) {
|
||||
.read = ::vfs_read,
|
||||
.write = ::vfs_write,
|
||||
.mkdir = ::vfs_mkdir,
|
||||
.stream = ::vfs_stream,
|
||||
.open = ::vfs_open,
|
||||
.list = ::vfs_list,
|
||||
.readRange = ::vfs_readRange,
|
||||
.readRanges = ::vfs_readRanges,
|
||||
.stream = ::vfs_stream,
|
||||
};
|
||||
}
|
||||
|
||||
@ -476,6 +556,40 @@ bool uf::vfs::stream( const uf::stl::string& path, size_t chunkSize, std::functi
|
||||
return false;
|
||||
}
|
||||
|
||||
pod::File uf::vfs::open( const uf::stl::string& path ) {
|
||||
uf::stl::string prefix, relative;
|
||||
uf::io::splitUri(path, prefix, relative);
|
||||
|
||||
for ( auto& mount : mounts ) {
|
||||
if ( prefix.empty() && mount.priority < 0 ) continue;
|
||||
if ( prefix.empty() || mount.prefix == prefix ) {
|
||||
if ( mount.open ) {
|
||||
pod::File file = mount.open( mount, relative );
|
||||
if ( file ) return file;
|
||||
}
|
||||
if ( mount.exists && mount.exists(mount, relative) ) {
|
||||
if ( mount.readRange && mount.size ) {
|
||||
FallbackFileState* state = new FallbackFileState{
|
||||
&mount,
|
||||
relative,
|
||||
0,
|
||||
mount.size(mount, relative)
|
||||
};
|
||||
|
||||
return pod::File{
|
||||
.handle = state,
|
||||
.read = fallback_file_read,
|
||||
.seek = fallback_file_seek,
|
||||
.tell = fallback_file_tell,
|
||||
.close = fallback_file_close
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return pod::File{};
|
||||
}
|
||||
|
||||
uf::stl::string uf::vfs::resolveBase( const uf::stl::string& path ) {
|
||||
uf::stl::string prefix, relative;
|
||||
uf::io::splitUri(path, prefix, relative);
|
||||
@ -497,6 +611,7 @@ uf::stl::string uf::vfs::resolveBase( const uf::stl::string& path ) {
|
||||
#define VFS_BASE "./data/"
|
||||
#endif
|
||||
|
||||
UF_VFS_MOUNT_CPP( uf::vfs::createDiskMount, "sys://", 999 );
|
||||
UF_VFS_MOUNT_CPP( uf::vfs::createDiskMount, "mdl://" VFS_BASE "models", 100 );
|
||||
UF_VFS_MOUNT_CPP( uf::vfs::createDiskMount, "scene://" VFS_BASE "scenes", 100 );
|
||||
UF_VFS_MOUNT_CPP( uf::vfs::createDiskMount, "ent://" VFS_BASE "entities", 100 );
|
||||
@ -504,7 +619,5 @@ UF_VFS_MOUNT_CPP( uf::vfs::createDiskMount, "tex://" VFS_BASE "textures", 100 );
|
||||
UF_VFS_MOUNT_CPP( uf::vfs::createDiskMount, "snd://" VFS_BASE "audio", 100 );
|
||||
UF_VFS_MOUNT_CPP( uf::vfs::createDiskMount, "spv://" VFS_BASE "shaders", 100 );
|
||||
UF_VFS_MOUNT_CPP( uf::vfs::createDiskMount, "lua://" VFS_BASE "scripts", 100 );
|
||||
|
||||
UF_VFS_MOUNT_CPP( uf::vfs::createDiskMount, "data://" VFS_BASE, 50 );
|
||||
UF_VFS_MOUNT_CPP( uf::vfs::createDiskMount, "", 0 );
|
||||
UF_VFS_MOUNT_CPP( uf::vfs::createDiskMount, "sys://", 999 );
|
||||
UF_VFS_MOUNT_CPP( uf::vfs::createDiskMount, "", 0 );
|
||||
@ -1,22 +1,43 @@
|
||||
#include <uf/utils/memory/allocator.h>
|
||||
#include <uf/utils/memory/pool.h>
|
||||
|
||||
bool uf::allocator::override = true;
|
||||
namespace impl {
|
||||
using alloc_func_t = void* (*)(size_t);
|
||||
using free_func_t = void (*)(void*, size_t);
|
||||
|
||||
void* uf::allocator::allocate( size_t n ) {
|
||||
if ( override && uf::memoryPool::global.size() > 0 ) {
|
||||
void* pool_alloc( size_t n ) {
|
||||
return uf::memoryPool::global.alloc( n );
|
||||
}
|
||||
return uf::allocator::malloc_m( n );
|
||||
void pool_free( void* p, size_t n ) {
|
||||
uf::memoryPool::global.free( p, n );
|
||||
}
|
||||
|
||||
#if UF_MEMORYPOOL_OVERRIDE_DEFAULT
|
||||
alloc_func_t alloc_fn = impl::pool_alloc;
|
||||
free_func_t free_fn = impl::pool_free;
|
||||
#else
|
||||
alloc_func_t alloc_fn = uf::allocator::malloc_m;
|
||||
free_func_t free_fn = uf::allocator::free_m;
|
||||
#endif
|
||||
}
|
||||
|
||||
void uf::allocator::override( bool state ) {
|
||||
if ( uf::memoryPool::global.size() == 0 ) state = false;
|
||||
if ( state ) {
|
||||
impl::alloc_fn = impl::pool_alloc;
|
||||
impl::free_fn = impl::pool_free;
|
||||
} else {
|
||||
impl::alloc_fn = uf::allocator::malloc_m;
|
||||
impl::free_fn = uf::allocator::free_m;
|
||||
}
|
||||
}
|
||||
|
||||
void* uf::allocator::allocate( size_t n ) {
|
||||
return impl::alloc_fn( n );
|
||||
}
|
||||
|
||||
void uf::allocator::deallocate( void* p, size_t n ) {
|
||||
if ( !p ) return;
|
||||
|
||||
if ( override && uf::memoryPool::global.size() > 0 ) {
|
||||
uf::memoryPool::global.free( p, n );
|
||||
}
|
||||
else uf::allocator::free_m( p );
|
||||
impl::free_fn( p, n );
|
||||
}
|
||||
|
||||
void* uf::allocator::malloc_m( size_t n ) {
|
||||
|
||||
@ -284,7 +284,7 @@ MANUAL_MALLOC:
|
||||
#if UF_MEMORYPOOL_INVALID_MALLOC
|
||||
alloc.size = 0; // orphaned
|
||||
alloc.pointer = (uintptr_t) uf::allocator::malloc_m(size);
|
||||
UF_MSG_DEBUG("allocating orphan: {} bytes at {}", size, (void*) alloc.pointer);
|
||||
//UF_MSG_DEBUG("allocating orphan: {} bytes at {}", size, (void*) alloc.pointer);
|
||||
|
||||
#if UF_MEMORYPOOL_STORE_ORPHANS
|
||||
pool.orphaned.emplace_back( alloc );
|
||||
@ -380,7 +380,7 @@ MANUAL_FREE:
|
||||
}
|
||||
|
||||
if ( it != pool.orphaned.end() ) {
|
||||
UF_MSG_DEBUG("manually freeing orphan {}", pointer);
|
||||
//UF_MSG_DEBUG("manually freeing orphan {}", pointer);
|
||||
uf::allocator::free_m( pointer );
|
||||
pool.orphaned.erase(it);
|
||||
return true;
|
||||
|
||||
@ -1,41 +1,71 @@
|
||||
#include <uf/utils/text/glyph.h>
|
||||
#if UF_USE_FREETYPE
|
||||
#include <stb_truetype.h>
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
|
||||
#if UF_USE_TRUETYPE
|
||||
|
||||
uint8_t* uf::glyph::generate( pod::Glyph& glyph, pod::FT_Glyph& g, uint64_t c, size_t size ) {
|
||||
ext::freetype::setPixelSizes( g, size );
|
||||
if ( !ext::freetype::load( g, c ) ) return NULL;
|
||||
uint8_t* uf::glyph::generate( pod::Glyph& glyph, pod::TrueTypeFont& g, uint64_t c, size_t size ) {
|
||||
ext::truetype::setPixelSizes( g, size );
|
||||
if ( !ext::truetype::load( g, c ) ) return NULL;
|
||||
return uf::glyph::generate( glyph, g );
|
||||
}
|
||||
|
||||
uint8_t* uf::glyph::generate( pod::Glyph& glyph, pod::FT_Glyph& g, const uf::stl::string& s, size_t size ) {
|
||||
ext::freetype::setPixelSizes( g, size );
|
||||
if ( !ext::freetype::load( g, s ) ) return NULL;
|
||||
uint8_t* uf::glyph::generate( pod::Glyph& glyph, pod::TrueTypeFont& g, const uf::stl::string& s, size_t size ) {
|
||||
ext::truetype::setPixelSizes( g, size );
|
||||
if ( !ext::truetype::load( g, s ) ) return NULL;
|
||||
return uf::glyph::generate( glyph, g );
|
||||
}
|
||||
|
||||
uint8_t* uf::glyph::generate( pod::Glyph& glyph, pod::FT_Glyph& g ) {
|
||||
if ( glyph.spread ) ext::freetype::setRenderMode( g, FT_RENDER_MODE_SDF );
|
||||
uint8_t* uf::glyph::generate( pod::Glyph& glyph, pod::TrueTypeFont& g ) {
|
||||
if ( !g.info ) return nullptr;
|
||||
stbtt_fontinfo* info = static_cast<stbtt_fontinfo*>(g.info);
|
||||
int c = static_cast<int>(g.current_codepoint);
|
||||
|
||||
glyph.size = { g.face->glyph->bitmap.width, g.face->glyph->bitmap.rows };
|
||||
glyph.bearing = { g.face->glyph->bitmap_left, g.face->glyph->bitmap_top };
|
||||
glyph.advance = { g.face->glyph->advance.x >> 6, g.face->glyph->advance.y >> 6 };
|
||||
int advance, lsb;
|
||||
stbtt_GetCodepointHMetrics(info, c, &advance, &lsb);
|
||||
|
||||
glyph.buffer.clear();
|
||||
int width, height, xoff, yoff;
|
||||
unsigned char* bitmap = nullptr;
|
||||
|
||||
const uint8_t* buffer = g.face->glyph->bitmap.buffer;
|
||||
|
||||
auto size = glyph.size + glyph.padding * 2;
|
||||
glyph.buffer.assign(size.x * size.y, 0);
|
||||
for ( size_t y = 0; y < glyph.size.y; ++y ) {
|
||||
const uint8_t* src = buffer + y * g.face->glyph->bitmap.pitch;
|
||||
for ( size_t x = 0; x < glyph.size.x; ++x ) {
|
||||
size_t dst = (y + glyph.padding.y) * size.x + (x + glyph.padding.x);
|
||||
glyph.buffer[dst] = src[x];
|
||||
}
|
||||
// this should never ever be called because I'll probably never get around to implementing SDFs in pure fixed-function OpenGL
|
||||
// but this causes issues with -flto on it
|
||||
#if !UF_ENV_DREAMCAST
|
||||
if ( glyph.spread > 0 ) {
|
||||
bitmap = stbtt_GetCodepointSDF(info, g.scale, c, glyph.padding.x, 128, static_cast<float>(glyph.spread), &width, &height, &xoff, &yoff);
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
bitmap = stbtt_GetCodepointBitmap(info, 0, g.scale, c, &width, &height, &xoff, &yoff);
|
||||
}
|
||||
|
||||
glyph.size = size;
|
||||
if ( !bitmap ) {
|
||||
width = height = xoff = yoff = 0;
|
||||
}
|
||||
|
||||
glyph.size = { static_cast<unsigned int>(width), static_cast<unsigned int>(height) };
|
||||
glyph.bearing = { xoff, -yoff };
|
||||
glyph.advance = { static_cast<int>(std::round(advance * g.scale)), 0 };
|
||||
|
||||
auto size_padded = glyph.size + glyph.padding * 2;
|
||||
glyph.buffer.assign(size_padded.x * size_padded.y, 0);
|
||||
|
||||
if ( bitmap ) {
|
||||
for ( size_t y = 0; y < glyph.size.y; ++y ) {
|
||||
const uint8_t* src = bitmap + y * width;
|
||||
for ( size_t x = 0; x < glyph.size.x; ++x ) {
|
||||
size_t dst = (y + glyph.padding.y) * size_padded.x + (x + glyph.padding.x);
|
||||
glyph.buffer[dst] = src[x];
|
||||
}
|
||||
}
|
||||
stbtt_FreeBitmap(bitmap, nullptr);
|
||||
}
|
||||
|
||||
glyph.size = size_padded;
|
||||
|
||||
#if UF_ENV_DREAMCAST
|
||||
//if ( glyph.spread > 0 ) uf::glyph::generateSdf( glyph );
|
||||
#endif
|
||||
|
||||
return glyph.buffer.data();
|
||||
}
|
||||
|
||||
@ -51,8 +51,8 @@ UF_VERTEX_DESCRIPTOR(GlyphVertex,
|
||||
|
||||
namespace {
|
||||
struct {
|
||||
#if UF_USE_FREETYPE
|
||||
pod::FT_Glyph face;
|
||||
#if UF_USE_TRUETYPE
|
||||
pod::TrueTypeFont face;
|
||||
uf::stl::unordered_map<uf::stl::string, uf::stl::unordered_map<size_t, pod::Glyph>> cache;
|
||||
#else
|
||||
char glyph;
|
||||
@ -156,7 +156,7 @@ uf::stl::vector<pod::GlyphBox> uf::glyph::calculateLayout( const uf::stl::vector
|
||||
auto& cache = ::glyphs.cache[metadata.font];
|
||||
|
||||
if ( cache.empty() ) {
|
||||
ext::freetype::initialize( ::glyphs.face, uf::io::root + "/fonts/" + metadata.font );
|
||||
ext::truetype::initialize( ::glyphs.face, uf::io::root + "/fonts/" + metadata.font );
|
||||
}
|
||||
|
||||
pod::Vector2f anchor = ::parseAnchor( metadata.alignment );
|
||||
@ -170,9 +170,9 @@ uf::stl::vector<pod::GlyphBox> uf::glyph::calculateLayout( const uf::stl::vector
|
||||
|
||||
// generate glyph and line height
|
||||
for ( const auto& token : tokens ) {
|
||||
std::u8string str(token.text.begin(), token.text.end());
|
||||
for ( uint64_t c : str ) {
|
||||
if ( c == '\n' || c == '\t' ) continue; // special characters
|
||||
for ( char raw_c : token.text ) {
|
||||
uint64_t c = static_cast<uint8_t>(raw_c); // Safely cast byte
|
||||
if ( c == '\n' || c == '\t' ) continue;
|
||||
|
||||
auto key = uf::glyph::hashSettings(c, metadata);
|
||||
auto& glyph = cache[key];
|
||||
@ -181,23 +181,25 @@ uf::stl::vector<pod::GlyphBox> uf::glyph::calculateLayout( const uf::stl::vector
|
||||
if ( glyph.buffer.empty() ) {
|
||||
glyph.padding = { metadata.padding[0], metadata.padding[1] };
|
||||
glyph.spread = metadata.spread;
|
||||
|
||||
uf::glyph::generate( glyph, ::glyphs.face, c, metadata.size );
|
||||
}
|
||||
|
||||
tallestGlyphY = std::max(tallestGlyphY, (float) glyph.size.y);
|
||||
totalWidth += glyph.size.x; // should probably be reset on new-line to find the widest line
|
||||
float g_y = static_cast<float>(glyph.size.y);
|
||||
if (g_y > tallestGlyphY) tallestGlyphY = g_y;
|
||||
|
||||
totalWidth += static_cast<float>(glyph.size.x);
|
||||
charCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if ( charCount > 0 ) averageTabWidth = (totalWidth / charCount) * 4.0f;
|
||||
if ( charCount > 0 ) averageTabWidth = (totalWidth / static_cast<float>(charCount)) * 4.0f;
|
||||
cursor.y = tallestGlyphY;
|
||||
|
||||
// calculate positions
|
||||
for ( const auto& token : tokens ) {
|
||||
std::u8string str( token.text.begin(), token.text.end() );
|
||||
for ( uint64_t c : str ) {
|
||||
for ( char raw_c : token.text ) {
|
||||
uint64_t c = static_cast<uint8_t>(raw_c);
|
||||
|
||||
// advance cursor on special characters
|
||||
if ( c == '\n' ) {
|
||||
cursor.y += tallestGlyphY;
|
||||
@ -214,25 +216,29 @@ uf::stl::vector<pod::GlyphBox> uf::glyph::calculateLayout( const uf::stl::vector
|
||||
// retrieve glyph
|
||||
auto key = uf::glyph::hashSettings(c, metadata);
|
||||
auto& glyph = cache[key];
|
||||
auto& g = layout.emplace_back(pod::GlyphBox{
|
||||
.box = {
|
||||
.x = cursor.x + glyph.bearing.x,
|
||||
.y = cursor.y - glyph.bearing.y,
|
||||
.w = glyph.size.x,
|
||||
.h = glyph.size.y,
|
||||
.z = 0,
|
||||
},
|
||||
.color = token.color,
|
||||
.anchor = anchor,
|
||||
.code = c,
|
||||
});
|
||||
|
||||
pod::GlyphBox newBox;
|
||||
newBox.box.x = cursor.x + static_cast<float>(glyph.bearing.x);
|
||||
newBox.box.y = cursor.y - static_cast<float>(glyph.bearing.y);
|
||||
newBox.box.w = static_cast<float>(glyph.size.x);
|
||||
newBox.box.h = static_cast<float>(glyph.size.y);
|
||||
newBox.box.z = 0.0f;
|
||||
newBox.color = token.color;
|
||||
newBox.anchor = anchor;
|
||||
newBox.code = c;
|
||||
|
||||
layout.push_back(newBox);
|
||||
pod::GlyphBox& g = layout.back();
|
||||
|
||||
// advance cursor
|
||||
cursor.x += glyph.advance.x;
|
||||
cursor.x += static_cast<float>(glyph.advance.x);
|
||||
|
||||
// advance bounding box
|
||||
maxTextWidth = std::max(maxTextWidth, g.box.x + g.box.w);
|
||||
maxTextHeight = std::max(maxTextHeight, g.box.y + g.box.h);
|
||||
// advance bounding box manually
|
||||
float right = g.box.x + g.box.w;
|
||||
if (right > maxTextWidth) maxTextWidth = right;
|
||||
|
||||
float bottom = g.box.y + g.box.h;
|
||||
if (bottom > maxTextHeight) maxTextHeight = bottom;
|
||||
}
|
||||
}
|
||||
|
||||
@ -246,10 +252,10 @@ uf::stl::vector<pod::GlyphBox> uf::glyph::calculateLayout( const uf::stl::vector
|
||||
g.box.y -= offsetY;
|
||||
|
||||
// normalize
|
||||
g.box.x /= ::defaults.size.x;
|
||||
g.box.w /= ::defaults.size.x;
|
||||
g.box.y /= ::defaults.size.y;
|
||||
g.box.h /= ::defaults.size.y;
|
||||
g.box.x /= static_cast<float>(::defaults.size.x);
|
||||
g.box.w /= static_cast<float>(::defaults.size.x);
|
||||
g.box.y /= static_cast<float>(::defaults.size.y);
|
||||
g.box.h /= static_cast<float>(::defaults.size.y);
|
||||
}
|
||||
|
||||
return layout;
|
||||
@ -260,7 +266,7 @@ bool uf::glyph::generateAtlas( const uf::stl::vector<pod::GlyphBox>& layout, con
|
||||
bool dirty = false;
|
||||
auto& cache = ::glyphs.cache[metadata.font];
|
||||
|
||||
#if UF_USE_FREETYPE
|
||||
#if UF_USE_TRUETYPE
|
||||
// generate atlas
|
||||
for ( const auto& g : layout ) {
|
||||
auto key = uf::glyph::hashSettings( g.code, metadata );
|
||||
|
||||
@ -1,3 +1,5 @@
|
||||
INCS += -I./dep/include/stb/ -I./dep/include/nlohmann/
|
||||
|
||||
ifneq (,$(findstring ffx:sdk,$(REQ_DEPS)))
|
||||
ifneq (,$(findstring vulkan,$(REQ_DEPS)))
|
||||
ifneq (,$(findstring gcc,$(REQ_DEPS)))
|
||||
@ -54,7 +56,6 @@ endif
|
||||
|
||||
ifneq (,$(findstring gltf,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_GLTF
|
||||
INCS += -I./dep/include/stb/ -I./dep/include/nlohmann/
|
||||
endif
|
||||
|
||||
ifneq (,$(findstring dc:texconv,$(REQ_DEPS)))
|
||||
@ -89,6 +90,10 @@ ifneq (,$(findstring freetype,$(REQ_DEPS)))
|
||||
DEPS += -lfreetype -lbz2
|
||||
endif
|
||||
|
||||
ifneq (,$(findstring ttf,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_TRUETYPE
|
||||
endif
|
||||
|
||||
ifneq (,$(findstring curl,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_CURL
|
||||
DEPS += -lcurl
|
||||
|
||||
@ -4,9 +4,9 @@ COMPILER = gcc
|
||||
CC = $(KOS_CC)
|
||||
CXX = $(KOS_CCPLUS)
|
||||
RENDERER = opengl
|
||||
OPTIMIZATIONS = -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -fstrict-aliasing -ffast-math -fno-unroll-all-loops -fno-optimize-sibling-calls -fschedule-insns2 -fomit-frame-pointer -DUF_NO_EXCEPTIONS -fno-exceptions -g -flto=auto -ffat-lto-objects
|
||||
OPTIMIZATIONS = -Os -ffunction-sections -fdata-sections -Wl,--gc-sections -fstrict-aliasing -ffast-math -fno-unroll-all-loops -fno-optimize-sibling-calls -fschedule-insns2 -fomit-frame-pointer -DUF_NO_EXCEPTIONS -fno-exceptions -g # -flto=auto -ffat-lto-objects -Wl,-Map=engine.map -Wl,--cref -fno-unwind-tables -fno-asynchronous-unwind-tables
|
||||
WARNINGS = -Wall -Wno-unknown-pragmas -Wno-unused-function -Wno-unused-variable -Wno-switch -Wno-reorder -Wno-sign-compare -Wno-unused-but-set-variable -Wno-ignored-attributes -Wno-narrowing -Wno-misleading-indentation -Wno-attributes -Wno-conversion-null
|
||||
FLAGS += $(KOS_CPPFLAGS) -m4-single -std=c++2b $(OPTIMIZATIONS) $(WARNINGS) -fdiagnostics-color=always
|
||||
FLAGS += $(KOS_CPPFLAGS) -m4-single -fdiagnostics-color=always
|
||||
|
||||
TARGET_EXTENSION = .elf
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
FLAGS += -DUF_ENV_DREAMCAST
|
||||
REQ_DEPS += opengl gldc json:nlohmann zlib lz4 lua simd ctti fmt freetype openal aldc ogg wav png # to-do: gut freetype to gut libpng
|
||||
REQ_DEPS += opengl gldc json:nlohmann zlib lz4 lua simd ctti fmt ttf ogg wav aica # openal aldc
|
||||
|
||||
INCS := -I./dep/dreamcast/include $(INCS)
|
||||
|
||||
@ -13,6 +13,9 @@ ifneq (,$(findstring aldc,$(REQ_DEPS)))
|
||||
DEPS += -lAL -lpthread
|
||||
FLAGS += -DUF_USE_OPENAL_ALDC -DUF_USE_ALUT
|
||||
endif
|
||||
ifneq (,$(findstring aica,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_AICA
|
||||
endif
|
||||
|
||||
ifneq (,$(findstring ogg,$(REQ_DEPS)))
|
||||
FLAGS += -DUF_USE_TREMOR
|
||||
@ -41,15 +44,12 @@ $(PREFIX): $(TARGET) ./bin/dreamcast/$(TARGET_NAME).cdi
|
||||
|
||||
$(EX_DLL): FLAGS += -DUF_EXPORTS
|
||||
$(EX_DLL): $(OBJS_DLL)
|
||||
$(KOS_AR) cru $@ $^
|
||||
$(KOS_RANLIB) $@
|
||||
cp $@ $(ENGINE_LIB_DIR)/$(PREFIX_PATH)/$(BASE_DLL)
|
||||
#cp $@ $(ENGINE_LIB_DIR)/$(PREFIX_PATH)/$(BASE_DLL)
|
||||
|
||||
$(EXT_EX_DLL): FLAGS += -DEXT_EXPORTS
|
||||
$(EXT_EX_DLL): $(OBJS_EXT_DLL)
|
||||
$(KOS_AR) cru $@ $^
|
||||
$(KOS_RANLIB) $@
|
||||
cp $@ $(ENGINE_LIB_DIR)/$(PREFIX_PATH)/$(BASE_EXT_DLL)
|
||||
#cp $@ $(ENGINE_LIB_DIR)/$(PREFIX_PATH)/$(BASE_EXT_DLL)
|
||||
|
||||
|
||||
./bin/dreamcast/romdisk.img:
|
||||
$(KOS_GENROMFS) -f ./bin/dreamcast/romdisk.img -d ./bin/dreamcast/romdisk/ -v
|
||||
@ -68,10 +68,10 @@ $(TARGET): $(OBJS) #./bin/dreamcast/romdisk.o
|
||||
cdi:
|
||||
cd ./bin/dreamcast/; ./elf2cdi.sh $(TARGET_NAME)
|
||||
|
||||
run-dreamcast:
|
||||
run-dc:
|
||||
$(KOS_EMU) ./bin/dreamcast/$(TARGET_NAME).cdi
|
||||
|
||||
run-debug-dreamcast:
|
||||
debug-dc:
|
||||
$(KOS_EMU_DEBUG) ./bin/dreamcast/$(TARGET_NAME).cdi $(TARGET).unstripped
|
||||
|
||||
clean-dreamcast:
|
||||
|
||||
@ -6,7 +6,7 @@ CXX = clang++
|
||||
OPTIMIZATIONS = -O3 -fstrict-aliasing -DUF_NO_EXCEPTIONS # -flto # -march=native
|
||||
WARNINGS = -Wall -Wno-pointer-arith -Wno-unused-function -Wno-unused-variable -Wno-switch -Wno-reorder-ctor -Wno-ignored-attributes -Wno-c++11-narrowing -Wno-unknown-pragmas -Wno-nullability-completeness -Wno-defaulted-function-deleted -Wno-mismatched-tags
|
||||
SANITIZE = -fsanitize=address # -fuse-ld=lld -fno-omit-frame-pointer
|
||||
FLAGS += -std=c++2b $(OPTIMIZATIONS) $(WARNINGS) $(SANITIZE) -fcolor-diagnostics -fansi-escape-codes
|
||||
FLAGS += $(SANITIZE) -fcolor-diagnostics -fansi-escape-codes
|
||||
|
||||
TARGET_EXTENSION =
|
||||
DLIB_EXTENSION = .so
|
||||
|
||||
@ -5,7 +5,7 @@ COMPILER = $(CC)
|
||||
CXX = g++
|
||||
OPTIMIZATIONS = -O3 -fstrict-aliasing -DUF_NO_EXCEPTIONS
|
||||
WARNINGS = -Wall -Wno-attributes -Wno-dangling-reference -Wno-unknown-pragmas -Wno-unused-function -Wno-unused-variable -Wno-switch -Wno-reorder -Wno-sign-compare -Wno-unused-but-set-variable -Wno-ignored-attributes -Wno-narrowing -Wno-misleading-indentation
|
||||
FLAGS += -std=c++2b $(OPTIMIZATIONS) $(WARNINGS) -fdiagnostics-color=always
|
||||
FLAGS += -fdiagnostics-color=always
|
||||
|
||||
TARGET_EXTENSION =
|
||||
DLIB_EXTENSION = .so
|
||||
|
||||
@ -3,7 +3,7 @@ ifneq (,$(findstring -DUF_DEV_ENV,$(FLAGS)))
|
||||
FLAGS += -march=native -g # -flto # -g
|
||||
endif
|
||||
|
||||
REQ_DEPS += $(RENDERER) json:nlohmann zlib lz4 luajit simd ctti gltf imgui fmt freetype openal ogg wav
|
||||
REQ_DEPS += $(RENDERER) json:nlohmann zlib lz4 luajit simd ctti gltf imgui fmt ttf openal ogg wav
|
||||
FLAGS += -DUF_ENV_LINUX -fPIC
|
||||
DEPS += -pthread -ldl -lX11 -lXrandr
|
||||
INCS := -I./dep/master/include $(INCS)
|
||||
|
||||
@ -6,7 +6,7 @@ CXX = clang++
|
||||
OPTIMIZATIONS = -O3 -fstrict-aliasing -DUF_NO_EXCEPTIONS # -flto # -march=native
|
||||
WARNINGS = -Wall -Wno-missing-braces -Wno-deprecated-literal-operator -Wno-pointer-arith -Wno-unused-function -Wno-unused-variable -Wno-switch -Wno-reorder-ctor -Wno-ignored-attributes -Wno-c++11-narrowing -Wno-unknown-pragmas -Wno-nullability-completeness -Wno-defaulted-function-deleted -Wno-mismatched-tags
|
||||
SANITIZE = -fuse-ld=lld # -fsanitize=address,undefined # -fuse-ld=lld -fno-omit-frame-pointer
|
||||
FLAGS += -std=c++2b $(OPTIMIZATIONS) $(WARNINGS) $(SANITIZE) -fcolor-diagnostics -fansi-escape-codes
|
||||
FLAGS += $(SANITIZE) -fcolor-diagnostics -fansi-escape-codes
|
||||
|
||||
# MSYS2
|
||||
INCS += -I/clang64/include/
|
||||
|
||||
@ -3,10 +3,9 @@ CDIR =
|
||||
CC = gcc
|
||||
COMPILER = $(CC)
|
||||
CXX = g++
|
||||
OPTIMIZATIONS = -O3 -fstrict-aliasing -DUF_NO_EXCEPTIONS -flto
|
||||
OPTIMIZATIONS = -O3 -fstrict-aliasing -DUF_NO_EXCEPTIONS # -flto
|
||||
WARNINGS = -Wall -Wno-unknown-pragmas -Wno-unused-function -Wno-unused-variable -Wno-switch -Wno-reorder -Wno-sign-compare -Wno-unused-but-set-variable -Wno-ignored-attributes -Wno-narrowing -Wno-misleading-indentation
|
||||
|
||||
FLAGS += -std=c++2b $(OPTIMIZATIONS) $(WARNINGS) -fdiagnostics-color=always
|
||||
FLAGS += -fdiagnostics-color=always
|
||||
|
||||
# MSYS2
|
||||
INCS += -I/mingw64/include/
|
||||
|
||||
@ -3,7 +3,7 @@ ifneq (,$(findstring -DUF_DEV_ENV,$(FLAGS)))
|
||||
FLAGS += -march=native -g # -flto # -g
|
||||
endif
|
||||
|
||||
REQ_DEPS += $(RENDERER) json:nlohmann zlib lz4 luajit simd ctti gltf imgui fmt freetype openal ogg wav
|
||||
REQ_DEPS += $(RENDERER) json:nlohmann zlib lz4 luajit simd ctti gltf imgui fmt ttf openal ogg wav
|
||||
FLAGS += -DUF_ENV_WINDOWS -DUF_ENV_WIN64 -DWIN32_LEAN_AND_MEAN
|
||||
DEPS += -lgdi32 -ldwmapi
|
||||
LINKS += #-Wl,-subsystem,windows
|
||||
|
||||
Loading…
Reference in New Issue
Block a user