Code Monkey home page Code Monkey logo

cute_headers's People

Contributors

aganm avatar andykt avatar captain4lk avatar cxong avatar dbohdan avatar dexp avatar dkorpel avatar egordorichev avatar empyreanx avatar felselva avatar greyvy avatar james-bern avatar kariem2k avatar kavika13 avatar m-r-hunt avatar mathewmariani avatar meshula avatar molguin92 avatar mupfdev avatar randomerrormessage avatar randygaul avatar ricop avatar robloach avatar roig avatar seemk avatar sigiesec avatar sro5h avatar themattrosen avatar to-miz avatar wizzard033 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cute_headers's Issues

WIN64 in tinyfiles

In TinyFiles I had to replace the line 54 with
#if defined( _WIN32 ) || defined ( _WIN64 )

for 64 bits compiling (on MVSC2015 and 2017 for sure).

You should add this on other header too.

It's not really important but it could be nice.

And thank's a lot for the work

tinyfiles.h wrong defines usage

In line 115:

#elif TF_PLATFORM == TF_MAC || TN_PLATFORM == TN_UNIX

should be:

#elif TF_PLATFORM == TF_MAC || TF_PLATFORM == TF_UNIX

Same in line 278 and 345

mingw support

Hi
i tried to compile tinysound example (sdl one) , but tons of errors appears !
does mingw considered as supported compiler for this library ?

Collision solving with c2Poly

I can't figure out how I am supposed to correctly resolve a collision between a c2Poly and a c2Circle.
For c2Circle vs c2AABB the following code worked:

c2CircletoAABBManifold(circle, aabb, &manifold);
circle.p.x += manifold.normal.x * manifold.depths[0];
circle.p.y += manifold.normal.y * manifold.depths[0];

Everything works as I expect and there is no 'jitter' when moving along the edges of the c2AABB. The same code also works for c2AABB vs c2Poly (except the problem below).

However if I do the same with the c2Poly (Note that I also have to substract this time):

c2CircletoPolyManifold(circle, poly, &manifold);
circle.p.x -= manifold.normal.x * manifold.depths[0];
circle.p.y -= manifold.normal.y * manifold.depths[0];

Then the c2Circle 'jumps' off the edges of the c2Poly (Using a c2AABB instead it works though):
peek 2017-06-20 19-21

Using just:

circle.p.x -= manifold.normal.x;
circle.p.y -= manifold.normal.y;

Works better but the movement of the c2Circle is 'jittery' along angled edges of the c2Poly (difficult to see in the recording).
peek 2017-06-20 19-23

Furthermore the c2AABB will jump around if one of its edges is moved towards a corner of the c2Poly:
peek 2017-06-20 19-18

Used c2Poly:

poly.count = 4;
poly.verts[0] = c2V(30, 30);
poly.verts[1] = c2V(130, 40);
poly.verts[2] = c2V(100, 80);
poly.verts[3] = c2V(40, 60);
c2MakePoly(&poly);

Ray to Circle collision broken

c2CircletoRay collision seems to be always broken.
My c2Ray & c2Circle:

c2Ray ray;
ray.p = c2V(100, 100);
ray.d = c2V(100, 100);
ray.t = 1;

c2Circle circle;
circle.r = 30;
circle.p = c2V(200, 200);

I get the impact with:

c2Raycast cast;
if (c2RaytoCircle(ray, circle, &cast)) {
        c2v impact = c2Impact(ray, cast.t);
}

The resulting impact is { 147.852, 147.852 }, which is outside the circle. In each case(circle position) I tested the resulting impact is always outside the circle.

cute_sound: Pitch Artifacts (SIMD Precision Issue) - Looking for Pull Request

I am having issues with playing the following (1.2 pitch setting):
http://www.particle-space.xyz/downloads/gong.ogg

Substituting the following resolved the issue:

__m128 phase; // = _mm_atan2_ps( imag, real );
float *phasef = (float*)&phase;
float *realf = (float*)ℜ
float *imagf = (float*)&imag;
for (int i=0; i<4; i++) phasef[i] = smbAtan2(imagf[i], realf[i]);

I suspect there is an issue with _mm_atan2_ps() related to the edge cases.

tinysound: Streaming OGG Files

OGG support in tinysound is done via stb_vorbis, which already has its own streaming API (more info here). Hooking up some code into tinysound to handle streaming would be a great feature to add.

This feature would be perfect for someone looking to contribute to tinysound! If tinysound is appealing, please consider adding a pull request.

My implementation suggestion would be to add another int field to tsLoadedSound to specify a streamed file (for values 0 and 1 to specify no stream, and streamed). Additional information like sample offsets can also be stored in this struct. Then within tsMix, on this line

tsLoadedSound* loaded = playing->loaded_sound;

The loaded sound can be examined and the stb_vorbis API can be used to perform streaming as necessary. This strategy would incur disk overhead into the mixing function, however, since most people will pop off a tsMix thread this is probably not a huge issue.

Core Audio Port

For OSX/iOS it looks like CoreAudio is the analog to DirectSound on Windows. tinysound is ready to be ported. A port would be a prime project for someone looking to contribute to open source. Here's how:

  • tsContext holds OS-specific pointers or handles.
  • tsMakeContext initializes tsContext and calls into OS-specific APIs.
  • tsShutdownContext frees any memory allocated in tsMakeContext, and calls into OS-specific APIs.
  • tsMix is platform independent, portable C code. However, it calls tsPosition and tsMemcpyToDS, both are platform specific to Windows DirectSound. These two functions will need to be deleted/rewritten using OS-specific APIs.

Summary: Loading the tsContext and shutting it down requires OS-specific code. Mixing is platform independent, and is just adding floats together then converting them into 16-bit integers. However, writing these 16-bit integers to the sound API is OS-specific (this writing out is what tsPosition and tsMemcpyToDS are for).

tinymath2d: C++ wrapper for tinyc2 functions

Considering the addition of tinymath2d i think it would be nice to have a C++ wrapper for tinyc2. I'm thinking of a base class c2Shape that holds the position information so the user could manipulate the position of a shape without knowing what type it is (which is something i am missing from tinyc2). Kind of like that:

namespace c2 {

struct Shape
{
        c2v position;
};

struct Aabb : public Shape
{
        float w;
        float h;
};

struct Circle : public Shape
{
        float r;
};

.
.
.

void collide(const Shape& A, const Shape& B, c2Manifold* m)
{
        // Calculate the manifold
}

}

One would need to cast the Shape to calculate the manifold then (either using the c API from tinyc2 or tinymath2d if possible). It would be nicer though to avoid the cast, but i can't think of way to do this right now.
Anyway just wanted to hear your opinion on that

TinySound thread issues..

Awesome speed improvement on the pitch code!

I noticed a few issues:

You will need a tsLock() for tsSetPitch() OR read playing->pitch just once in tsMix()? In tsPlaySound() you will need an unlock:

if ( !playing )
{
	tsUnlock( ctx );
	return 0;
}

tsStopAllSounds() is not thread safe with tsMix()
A possible solution:

void tsStopAllSounds( tsContext* ctx )
{
        tsLock( ctx );
	tsPlayingSound* sound = ctx->playing;
	while ( sound )
	{
		// let tsMix() remove the sound
                sound->active = 0;
		sound = sound->next;
	}
        tsUnlock( ctx );
}

tinyc2 cannot be used in C code

In few places it uses C++ syntax:

  • true bool literal in line 802
  • C++11 list initialization in line 1422
  • C++11 list initialization in line 1459 (from C2_PLANE_AT macro)

Time library error

I have checked your tinytime.h library and found one error. This error is in linux realization. Sometimes, returned delta time is less than 0. It happens every second. And i think error is in nanoseconds only. There should be also seconds. Sorry for my english. Just look to code, it can look like this:

float delta = (float) (double)(end.tv_sec - start.tv_sec) + ((double)(end.tv_nsec - start.tv_nsec) * 1.0e-9);

c2RaytoAABB missing check if cast.t < 0

I just did some more testing and found out that if the c2AABB is over ray.p then c2Raycast::t is negative.
Here are my c2Ray and c2AABB:

c2AABB aabb;
aabb.min = c2V(80, 80);
aabb.max = c2V(120, 120);

c2Ray ray;
ray.p = c2V(100, 100);
ray.d = c2V(100, 100);
ray.t = 1;

I included a picture to illustrate the problem.
screenshot from 2017-06-19 10-36-05
PS: I hope it's ok if I keep opening issues for the bugs I find :)

tinysound SDL: only right channel works

Both Linux and Windows. I just compiled the demo with Visual Studio 2017 on Windows.
You can clearly hear it with headphones: left channel is always silent.

If change wanted.channels to 1, then both left and right have a sound, but 2 times slower than normal.

P.S. The demo can't be compiled in VS. You need to change 636 line from:

void* buf = data;

to:

char* buf = (char*)data;

tinyc2: Inconsistent normal direction if using c2Collide

If you use c2Collide to calculate the c2Manifold of a collision, the normal doesn't always point from shape A to B, if the type of A is different from the type of B. If both are of the same type the normal always points from A to B. This happens because the arguments of c2XtoX functions for different shape types have a fixed order.
E.g. Shape A is a c2Circle and B is a c2AABB.

// If passed in this order the normal will point from A -> B.
c2Collide(&A, NULL, C2_CIRCLE, &B, NULL, C2_AABB, &manifold);

Now switch the shapes, A now is a c2AABB and B a c2Circle

// Now c2Collide will call c2CircletoAABBManifold(*B, *A, manifold)
// If passed in this order the normal will point from B -> A.
c2Collide(&A, NULL, C2_AABB, &B, NULL, C2_CIRCLE, &manifold);

A simple solution would be: For each call in c2Collide where A and B are switched (e.g. c2XtoX(*B, *A, &m)) the normal needs to be inverted.

stb_vorbis example

Most people would probably use stb_vorbis with tinysound, so it would be good for me to see if a demo, or maybe a support function, would be a good addition.

Make load wav accept a buffer instead of path

This is generally a much better idea since not everyone who will use your api will be wanting to load stuff from disk. If you just let them provide you a buffert then they can pick if they want file-loading or memory-streaming or whatever.

Really nice API btw :)

tmseek - potential memory access bug

In tinymemfile all offsets are signed integers and there is an ambiguity in tmseek. Assert's body suggests that smseek will add offset to the current bytes_read and checks if greater than zero but smseek overwrites bytes_read with offset. Consider two scenarios:

  1. assert error
fp->bytes_read = 0;
tmseek(fp, MAX_INT); // assert ok, bytes_read + offset >= 0;
                     // assign ok, will set bytes_read to MAX_INT - a valid memory offset
tmseek(fp, 1);       // assert error,  bytes_read + offset < 0;
                     // assign ok, will set bytes-read to 1 - still a valid offset
  1. assign error
fp->bytes_read = 0;
tmseek(fp, MAX_INT); // assert ok, bytes_read + offset >= 0;
                     // assign ok, will set bytes_read to MAX_INT - a valid memory offset
tmseek(fp, -1);      // assert ok,  bytes_read + offset >= 0;
                     // assign error, will set bytes-read to -1 - not a valid offset

dotc integration?

@RandyGaul I love this collection of small, useful, tight header files! I'm using tinyc2 in a game project right now.

I'm wondering if you'd be open to a PR that integrates dotc: https://www.npmjs.com/package/dotc

The tl;dr is it's a preprocessor that copies the semantics of node's module lookup algorithm without modifying anything else about the c language.

What's really nice about this is you can expose only the things that you want to be available from your module and everything else stays private, (i.e., not in the global namespace.)

If this is something you'd be interested in I'd be happy to send a PR (would basically look like this:)

#ifdef DOTC
#export c2AABB
#export c2Ray
#export c2Circle
#export c2CircletoCircle
// etc....
#endif

Extra #endif in tinyfiles.h

I think there's an extra #endif in tinyfiles.h. Around line 88 there's this:

#if defined( TINYPATH_IMPLEMENTATION )
#endif TINYPATH_IMPLEMENTATION

That #endif doesn't look like it should be there. I get compilation errors about the final #endif having no matching #if

Standardize IMPL vs IMPLEMENTATION define

Some headers use LIBNAME_IMPL and some use LIBNAME_IMPLEMENTATION. Sometimes they just use the lib's acronym like TS_IMPL instead of TINYSOUND_IMPLEMENTATION.

Should standardize to: LIBENAME_IMPLEMENTATION for consistency. Should document each one of these in a consistent spot.

tsMix SIMD

Should use SSE + SSE2 in the tsMix function. tinysound was written with SIMD in mind so this should be a nearly one-to-one conversion.

Compiling tinyc2 on Mac OSX

Hey.

I used tinyc2 for a gamejam project and had same issues compiling it on my friend's Apple laptop.
I don't know anything about versions of his stuff.

I'll post a diff here if you are at all interested in this. The changes were minimal.
I'm sorry that line numbers aren't included, also I don't have the energy or time to make a proper diff or Github pull request.

diff linux_gamejam_2017_kopi/tinyc2.h linux_gamejam_2017_original/tinyc2.h
1357c1357
< #define C2_PLANE_AT( p, i ) (c2h){ (p)->norms[ i ], c2Dot( (p)->norms[ i ], (p)->verts[ i ] ) }
---
> #define C2_PLANE_AT( p, i ) { (p)->norms[ i ], c2Dot( (p)->norms[ i ], (p)->verts[ i ] ) }
1422c1422
< 	if ( h ) *h = (c2h){ c2CCW90( in ), c2Dot( c2CCW90( in ), ra ) };
---
> 	if ( h ) *h = { c2CCW90( in ), c2Dot( c2CCW90( in ), ra ) };

tinysound: Feedback and Feature Requests

Ok, I've trying to integrate tinysound for some time, and just realized that it still lacks certain features I'd consider essential to a game.

  1. Streaming

The ogg/wav files are essentially loaded wholesale into memory as far as I can see. Load times thus suffer hard; and you can't always have all your sounds loaded at initialization time (I have ~200megs of sound, some of them are 5mb+). You can keep the file pointers (or oggstreams) in your tinysound structs, and stream the data using the mixer thread.

  1. FreeSound() troubles

I'm using the lower level apis, and a separate thread for mixing, pools set to 0. When I call FreeSound() in the main loop upon a keypress (with the intention of playing another piece of ambient music), FreeSound() does not remove the playingsound pointer from the context's playing list. The examples don't test for such a case either - they all call FreeSound() at termination.

  1. Music not playing on global focus (Windows)

Minor detail, but give an option to add DSBCAPS_GLOBALFOCUS to bufdesc.dwFlags for the secondary buffer on line 883, which allows music to be playing while the window is not focused.

All in all, tinysound isn't quite production ready yet. I can't quite consider it at version 1.0.

Conversion

Randy, to correctly convert from nanoseconds to seconds on Linux change this line

float elapsed = (float)((double)(now.tv_nsec - prev.tv_nsec) * 1e9);

to

float elapsed = (float)((double)(now.tv_nsec - prev.tv_nsec) * 1e-9);

tinyfiles.h compile error

tinyfiles.h(267): error C4996: 'strerror': This function or variable may be unsafe. Consider using strerror_s instead.

Errors out on wave files with fact chunk

Line 566 assumes the first chunk will be a data chunk, but this is not always the case.

In my case, I have a wav file with a fact chunk, and the load routine errors out.

tinysound demos port

Most of the tinysound demos don't run on Apple machines. The only one that does right now is the pitch demo. Demos need to be updated so they can run on OSX/iOS as well as Windows.

GCC 'selectany' attribute warning

tinysound.h:2102:1: warning: 'selectany' attribute directive ignored [-Wattributes]
 _PS_CONST_TYPE( sign_mask, int, (int)0x80000000 );
 ^~~~~~~~~~~~~~
tinysound.h:2103:1: warning: 'selectany' attribute directive ignored [-Wattributes]
 _PS_CONST_TYPE( inv_sign_mask, int, (int)~0x80000000 );
 ^~~~~~~~~~~~~~

It's related to following line:

	#define TS_SELECTANY const __attribute__( (selectany) )

How to fix it better?

GCC info:

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/7.1.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc-multilib/src/gcc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=https://bugs.archlinux.org/ --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --enable-multilib --disable-werror --enable-checking=release --enable-default-pie --enable-default-ssp
Thread model: posix
gcc version 7.1.1 20170630 (GCC)

Compilation of tiny2c.h fails under g++

When compiling under linux g++ complains about memcpy not being declared:

In file included from main.cpp:4:0:
./tinyc2.h: In function ‘int c2Hull(c2v*, int)’:
./tinyc2.h:913:55: error: ‘memcpy’ was not declared in this scope
  memcpy( verts, hull_verts, sizeof( c2v ) * out_count );

Including cstring before tiny2c.h fixes the error.

Os: Ubuntu 16.04 LTS
Compiler: g++ (Ubuntu 6.2.0-5ubuntu12) 6.2.0 20161005

Ray to Poly collision broken

c2RaytoPoly collision seems to be broken if the polygon is perpendicular towards the ray. As demonstrated in below gif:

brokenraygif

(the green lines are rays currently not colliding with anything, black lines are rays colliding with the box)

Standardize custom allocator and CRT support

Each header should have consistency for custom malloc/free implementations. Each one should be able to take a context pointer. Should be documented at top of header for ease to find.

tinysound port to Linux

If you enjoyed these headers please consider contributing a Linux audio port of tinysound :)

tinysound cannot run on Linux. Right now only Windows/Apple are supported through DirectSound and CoreAudio. tinysound is ready to be ported. A port would be a prime project for someone looking to contribute to open source. Here's how:

  • tsContext holds OS-specific pointers or handles.
  • tsMakeContext initializes tsContext and calls into OS-specific APIs.
  • tsShutdownContext frees any memory allocated in tsMakeContext, and calls into OS-specific APIs.
  • tsMix is platform independent, portable C code. However, it calls tsPosition and tsMemcpyToDS, both are platform specific to Windows DirectSound. These two functions will need to be deleted/rewritten using OS-specific APIs. There are also similar calls to CoreAudio specific functions.

Summary: Loading the tsContext and shutting it down requires OS-specific code. Mixing is platform independent, and is just adding floats together then converting them into 16-bit integers. However, writing these 16-bit integers to the sound API is OS-specific.

Macro C2_PLANE_AT error

The macro C2_PLANE_AT, defined at https://github.com/RandyGaul/tinyheaders/blob/ff76ac374a6bec431d8748a82f91ec44f2952d96/tinyc2.h#L1357 raises the following error on GCC 6.3.1, Linux:

tinyc2.h: In functionc2AntinormalFace’:
tinyc2.h:1357:29: error: expected expression before ‘{’ token
 #define C2_PLANE_AT( p, i ) { (p)->norms[ i ], c2Dot( (p)->norms[ i ], (p)->verts[ i ] ) }
                             ^

I think that multi-statement macros aren't ANSI/ISO C/C++, that's why it works on Visual Studio, but not on GCC. Since the macro is used in many places, the only solution I can think of is to replace it with a function or replace where the macro is used with the explicit code.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.