/include/proc.h (e648e6df4d9c52022fa120c51fed08af032fe38c) (2010 bytes) (mode 100644) (type blob)
#ifndef PROC_H
#define PROC_H
#include <assert.h>
#include <stdint.h>
#include <utility>
#include <vector>
namespace proc {
// Xorshift32 generator. Does not decorrelate automatically. User
// should run it a few hundred times for a better seed.
uint32_t Xorshift32( uint32_t *seed );
// Returns a float from 0 (inclusive) to 1 (exclusive).
float RandFloat( uint32_t *seed );
// Returns true or false.
bool CoinFlip( uint32_t *seed );
// Returns -1 to 1 inclusive.
int DF( uint32_t *seed );
// Returns 1 to n inclusive.
int DN( uint32_t *seed, int n );
// Returns a randomly selected member of objects.
template<typename T>
inline T RandObject( uint32_t *seed, const std::vector<T> &objects ){
return objects[(size_t)( RandFloat( seed ) * objects.size() )];
}
// Returns a member via Monte Carlo sampling of the assigned
// probabilities of objects.
template<typename T>
inline T ProbObject(
uint32_t *seed,
const std::vector<std::pair<T,float>> &objects ){
float total = 0.0f;
for( auto &o : objects ){
// Assert if NaN or less than 0 to avoid other problems.
assert( o.second == o.second && o.second >= 0.0f );
total += o.second;
}
float slot = 0.0f, ball = RandFloat( seed ) * total;
for( auto &o : objects ){
if( ball >= slot && ball < slot + o.second ) return o.first;
slot += o.second;
}
// Default case: Return the first member.
return objects[0].first;
}
#ifdef PROC_IMPLEMENTATION
uint32_t Xorshift32( uint32_t *seed ){
uint32_t x = *seed;
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
return ( *seed = x );
}
float RandFloat( uint32_t *seed ){
return
(double)Xorshift32( seed ) / ( (double)0xFFFFFFFF + 1.0 );
}
bool CoinFlip( uint32_t *seed ){
return RandFloat( seed ) < 0.5f;
}
int DF( uint32_t *seed ){
return (int)( RandFloat( seed ) * 3 ) - 1;
}
int DN( uint32_t *seed, int n ){
return (int)( RandFloat( seed ) * n ) + 1;
}
#endif // PROC_IMPLEMENTATION
} // namespace proc
#endif // PROC_H
Mode |
Type |
Size |
Ref |
File |
100644 |
blob |
98 |
227abf3bfa53b2530dcc74495da7bd0ccdcb0775 |
.gitignore |
100644 |
blob |
225 |
9b00c2c2e7b4f0c1e338fdead65f17ba0af089c1 |
COPYING |
100755 |
blob |
43 |
45aea818a4a3202b2467509f28a481cce08834d2 |
Confectioner.command |
100644 |
blob |
14015 |
649b7f0c112c3ac13287bfe88b949fec50356e4d |
Makefile |
100644 |
blob |
2723 |
b5a3f573f076ef740ca742ec9598043732e10c0e |
README.md |
040000 |
tree |
- |
6b3a1677d07517c1f83769dd7675fe6bb9d7a269 |
base |
100755 |
blob |
156 |
84cb1387849f2ca98e53e43536d00af2dfabf7d3 |
caveconfec |
100755 |
blob |
28 |
41b0ef285892c86306eaa269f366dd04cb633d21 |
caveconfec.bat |
100644 |
blob |
198037 |
a0180394c9bf29c02b7ef05916bd5573e3f37da2 |
confec.cpp |
100644 |
blob |
487269 |
29cfd3578eb40b1f039e271bcaa81af49d1b7f3c |
gamecontrollerdb.txt |
040000 |
tree |
- |
62e9d686bbab52d3d88886390b437a3ecef315de |
include |
100755 |
blob |
12081 |
ad29f012941aedfd4ee7232ed95fb68c8c5244c9 |
index-template.html |
100755 |
blob |
1065 |
a460e3c74b8fa53a6f609944ef7e41558479e73f |
libs.cpp |
100755 |
blob |
27581 |
8350a63e947e8a4a55608fd090d128fef7b969a1 |
micropather.cpp |
100644 |
blob |
141235 |
f54e2d2631a628876a631456c043b77da5db78bd |
openjdk.pem |
100755 |
blob |
8 |
e9a74187b02a27b165dfa4f93bf6f060376d0ee6 |
steam_appid.txt |
Hints:
Before first commit, do not forget to setup your git environment:
git config --global user.name "your_name_here"
git config --global user.email "your@email_here"
Clone this repository using HTTP(S):
git clone https://rocketgit.com/user/mse/ConfectionerEngine
Clone this repository using ssh (do not forget to upload a key first):
git clone ssh://rocketgit@ssh.rocketgit.com/user/mse/ConfectionerEngine
Clone this repository using git:
git clone git://git.rocketgit.com/user/mse/ConfectionerEngine
You are allowed to anonymously push to this repository.
This means that your pushed commits will automatically be transformed into a
merge request:
... clone the repository ...
... make some changes and some commits ...
git push origin main