Browse Source

Add pseudorandom functions for floats.

legacy
Sam Hocevar sam 14 years ago
parent
commit
0dfc497814
8 changed files with 62 additions and 15 deletions
  1. +1
    -1
      src/Makefile.am
  2. +1
    -0
      src/core.h
  3. +0
    -14
      src/matrix.h
  4. +52
    -0
      src/numeric.h
  5. +1
    -0
      win32/deushax.vcxproj
  6. +3
    -0
      win32/deushax.vcxproj.filters
  7. +1
    -0
      win32/monsterz.vcxproj
  8. +3
    -0
      win32/monsterz.vcxproj.filters

+ 1
- 1
src/Makefile.am View File

@@ -8,7 +8,7 @@ liblol_a_SOURCES = \
forge.cpp forge.h video.cpp video.h timer.cpp timer.h bitfield.h \
profiler.cpp profiler.h input.h input.cpp world.cpp world.h \
sample.cpp sample.h sampler.cpp sampler.h text.cpp text.h \
emitter.cpp emitter.h \
emitter.cpp emitter.h numeric.h \
\
sdlinput.cpp sdlinput.h \
\


+ 1
- 0
src/core.h View File

@@ -18,6 +18,7 @@

// Base types
#include "matrix.h"
#include "numeric.h"
#include "timer.h"

// Static classes


+ 0
- 14
src/matrix.h View File

@@ -140,19 +140,5 @@ typedef Vec3<int> Int3;
GLOBALS(2)
GLOBALS(3)

/* A few utility functions */
template <typename T> static inline T PotUp(T val)
{
val = val - 1;
//if (sizeof(val) > 8) val = val | (val >> 64);
//if (sizeof(val) > 4) val = val | (val >> 32);
if (sizeof(val) > 2) val = val | (val >> 16);
if (sizeof(val) > 1) val = val | (val >> 8);
val = val | (val >> 4);
val = val | (val >> 2);
val = val | (val >> 1);
return val + 1;
}

#endif // __DH_MATRIX_H__


+ 52
- 0
src/numeric.h View File

@@ -0,0 +1,52 @@
//
// Lol Engine
//
// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
// This program is free software; you can redistribute it and/or
// modify it under the terms of the Do What The Fuck You Want To
// Public License, Version 2, as published by Sam Hocevar. See
// http://sam.zoy.org/projects/COPYING.WTFPL for more details.
//

//
// The Matrix classes
// ------------------
//

#if !defined __DH_NUMERIC_H__
#define __DH_NUMERIC_H__

#include <cmath>
#include <cstdlib>

/* Random float value */
static inline float RandF()
{
return (float)rand() / RAND_MAX;
}

static inline float RandF(float val)
{
return RandF() * val;
}

static inline float RandF(float min, float max)
{
return min + RandF() * (max - min);
}

/* Next power of two. */
template <typename T> static inline T PotUp(T val)
{
val = val - 1;
if (sizeof(val) > 4) val = val | ((uint64_t)val >> 32);
if (sizeof(val) > 2) val = val | ((uint64_t)val >> 16);
if (sizeof(val) > 1) val = val | ((uint64_t)val >> 8);
val = val | ((uint64_t)val >> 4);
val = val | ((uint64_t)val >> 2);
val = val | ((uint64_t)val >> 1);
return val + 1;
}

#endif // __DH_NUMERIC_H__


+ 1
- 0
win32/deushax.vcxproj View File

@@ -29,6 +29,7 @@
<ClInclude Include="..\src\layer.h" />
<ClInclude Include="..\src\map.h" />
<ClInclude Include="..\src\matrix.h" />
<ClInclude Include="..\src\numeric.h" />
<ClInclude Include="..\src\profiler.h" />
<ClInclude Include="..\src\sample.h" />
<ClInclude Include="..\src\sampler.h" />


+ 3
- 0
win32/deushax.vcxproj.filters View File

@@ -51,6 +51,9 @@
<ClInclude Include="..\src\matrix.h">
<Filter>lolengine</Filter>
</ClInclude>
<ClInclude Include="..\src\numeric.h">
<Filter>lolengine</Filter>
</ClInclude>
<ClInclude Include="..\src\profiler.h">
<Filter>lolengine</Filter>
</ClInclude>


+ 1
- 0
win32/monsterz.vcxproj View File

@@ -32,6 +32,7 @@
<ClInclude Include="..\src\layer.h" />
<ClInclude Include="..\src\map.h" />
<ClInclude Include="..\src\matrix.h" />
<ClInclude Include="..\src\numeric.h" />
<ClInclude Include="..\src\profiler.h" />
<ClInclude Include="..\src\sample.h" />
<ClInclude Include="..\src\sampler.h" />


+ 3
- 0
win32/monsterz.vcxproj.filters View File

@@ -51,6 +51,9 @@
<ClInclude Include="..\src\matrix.h">
<Filter>lolengine</Filter>
</ClInclude>
<ClInclude Include="..\src\numeric.h">
<Filter>lolengine</Filter>
</ClInclude>
<ClInclude Include="..\src\profiler.h">
<Filter>lolengine</Filter>
</ClInclude>


Loading…
Cancel
Save