mirror of
https://github.com/hrydgard/ppsspp.git
synced 2026-11-17 11:24:27 +01:00
Add some old code, do some buildfixing
This commit is contained in:
1 parent
7e2e7856d8
commit
a67237fba7
22 files changed
+286
-46
No files matched your search
@@ -0,0 +1,17 @@
|
||||
#include "base/backtrace.h"
|
||||
|
||||
#ifndef _MSC_VER
|
||||
|
||||
// LINUX ONLY
|
||||
|
||||
#include <execinfo.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void *backtrace_buffer[128];
|
||||
|
||||
void PrintBacktraceToStderr() {
|
||||
int num_addrs = backtrace(backtrace_buffer, 128);
|
||||
backtrace_symbols_fd(backtrace_buffer, num_addrs, STDERR_FILENO);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,3 @@
|
||||
#pragma once
|
||||
|
||||
void PrintBacktraceToStderr();
|
||||
@@ -0,0 +1,37 @@
|
||||
#pragma once
|
||||
|
||||
// An inline fastlist is a fixed size array with a position counter.
|
||||
// Objects stored in a fastlist must be copyable.
|
||||
// [] returns the objects in consecutive order, up to and not including
|
||||
// the value of .size().
|
||||
// Order is not preserved when removing objects.
|
||||
template<class T, int max_size>
|
||||
class InlineFastList {
|
||||
public:
|
||||
InlineFastList() : count_(0) {}
|
||||
~InlineFastList() {}
|
||||
|
||||
T& operator [](int index) { return data_[index]; }
|
||||
const T& operator [](int index) const { return data_[index]; }
|
||||
int size() const { return count_; }
|
||||
|
||||
void Add(T t) {
|
||||
data_[count_++] = t;
|
||||
}
|
||||
void RemoveAt(int index) {
|
||||
data_[index] = data_[count_ - 1];
|
||||
count_--;
|
||||
}
|
||||
void Remove(T t) { // Requires operator==
|
||||
for (int i = 0; i < count_; i++) {
|
||||
if (data_[i] == t) {
|
||||
RemoveAt(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
T data_[max_size];
|
||||
int count_;
|
||||
};
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "base/fastlist.h"
|
||||
#include "base/logging.h"
|
||||
|
||||
/*
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(fastlist, AddRemove) {
|
||||
InlineFastList<int, 8> list;
|
||||
list.Add(8);
|
||||
list.Remove(7);
|
||||
EXPECT_EQ(1, list.size());
|
||||
list.Remove(8);
|
||||
EXPECT_EQ(0, list.size());
|
||||
list.Add(1);
|
||||
list.Add(2);
|
||||
list.Add(3);
|
||||
EXPECT_EQ(3, list.size());
|
||||
}
|
||||
*/
|
||||
@@ -0,0 +1,113 @@
|
||||
// From http://ootips.org/yonat/4dev/linked_ptr.h
|
||||
|
||||
/*
|
||||
* linked_ptr - simple reference linked pointer
|
||||
* (like reference counting, just using a linked list of the references
|
||||
* instead of their count.)
|
||||
*
|
||||
* The implementation stores three pointers for every linked_ptr, but
|
||||
* does not allocate anything on the free store.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
/* For ANSI-challenged compilers, you may want to #define
|
||||
* NO_MEMBER_TEMPLATES, explicit or mutable */
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define NO_MEMBER_TEMPLATES
|
||||
#endif
|
||||
|
||||
template <class X> class linked_ptr
|
||||
{
|
||||
public:
|
||||
|
||||
#ifndef NO_MEMBER_TEMPLATES
|
||||
# define TEMPLATE_FUNCTION template <class Y>
|
||||
TEMPLATE_FUNCTION friend class linked_ptr<Y>;
|
||||
#else
|
||||
# define TEMPLATE_FUNCTION
|
||||
typedef X Y;
|
||||
#endif
|
||||
|
||||
typedef X element_type;
|
||||
|
||||
explicit linked_ptr(X* p = 0) throw()
|
||||
: itsPtr(p) {itsPrev = itsNext = this;}
|
||||
~linked_ptr()
|
||||
{release();}
|
||||
linked_ptr(const linked_ptr& r) throw()
|
||||
{acquire(r);}
|
||||
linked_ptr& operator=(const linked_ptr& r)
|
||||
{
|
||||
if (this != &r) {
|
||||
release();
|
||||
acquire(r);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
#ifndef NO_MEMBER_TEMPLATES
|
||||
template <class Y> friend class linked_ptr<Y>;
|
||||
template <class Y> linked_ptr(const linked_ptr<Y>& r) throw()
|
||||
{acquire(r);}
|
||||
template <class Y> linked_ptr& operator=(const linked_ptr<Y>& r)
|
||||
{
|
||||
if (this != &r) {
|
||||
release();
|
||||
acquire(r);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
#endif // NO_MEMBER_TEMPLATES
|
||||
|
||||
X& operator*() const throw() {return *itsPtr;}
|
||||
X* operator->() const throw() {return itsPtr;}
|
||||
X* get() const throw() {return itsPtr;}
|
||||
bool unique() const throw() {return itsPrev ? itsPrev==this : true;}
|
||||
|
||||
private:
|
||||
X* itsPtr;
|
||||
mutable const linked_ptr* itsPrev;
|
||||
mutable const linked_ptr* itsNext;
|
||||
|
||||
void acquire(const linked_ptr& r) throw()
|
||||
{ // insert this to the list
|
||||
itsPtr = r.itsPtr;
|
||||
itsNext = r.itsNext;
|
||||
itsNext->itsPrev = this;
|
||||
itsPrev = &r;
|
||||
#ifndef mutable
|
||||
r.itsNext = this;
|
||||
#else // for ANSI-challenged compilers
|
||||
(const_cast<linked_ptr<X>*>(&r))->itsNext = this;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef NO_MEMBER_TEMPLATES
|
||||
template <class Y> void acquire(const linked_ptr<Y>& r) throw()
|
||||
{ // insert this to the list
|
||||
itsPtr = r.itsPtr;
|
||||
itsNext = r.itsNext;
|
||||
itsNext->itsPrev = this;
|
||||
itsPrev = &r;
|
||||
#ifndef mutable
|
||||
r.itsNext = this;
|
||||
#else // for ANSI-challenged compilers
|
||||
(const_cast<linked_ptr<X>*>(&r))->itsNext = this;
|
||||
#endif
|
||||
}
|
||||
#endif // NO_MEMBER_TEMPLATES
|
||||
|
||||
void release()
|
||||
{ // erase this from the list, delete if unique
|
||||
if (unique()) delete itsPtr;
|
||||
else {
|
||||
itsPrev->itsNext = itsNext;
|
||||
itsNext->itsPrev = itsPrev;
|
||||
itsPrev = itsNext = 0;
|
||||
}
|
||||
itsPtr = 0;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -7,8 +7,6 @@
|
||||
#define LEFT 1
|
||||
#define MIDDLE 2
|
||||
|
||||
namespace lin {
|
||||
|
||||
static const float flt_plus_inf = -logf(0); // let's keep C and C++ compilers happy.
|
||||
|
||||
AABB::AABB() : minB(0,0,0),maxB(0,0,0) {
|
||||
@@ -268,5 +266,3 @@ bool AABB::BehindPlane(const Plane &plane) const {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
} // namespace lin
|
||||
+2
-9
@@ -1,11 +1,8 @@
|
||||
#ifndef _MATH_LIN_AABB
|
||||
#define _MATH_LIN_AABB
|
||||
#pragma once
|
||||
|
||||
#include "math/lin/vec3.h"
|
||||
|
||||
namespace lin {
|
||||
|
||||
class Ray;
|
||||
struct Ray;
|
||||
class Plane;
|
||||
|
||||
struct AABB {
|
||||
@@ -41,7 +38,3 @@ struct AABB {
|
||||
|
||||
bool BehindPlane(const Plane &plane) const;
|
||||
};
|
||||
|
||||
} // namespace lin
|
||||
|
||||
#endif // _MATH_LIN_AABB
|
||||
+1
-4
@@ -1,13 +1,10 @@
|
||||
#include "math/lin/matrix4x4.h"
|
||||
#include "math/lin/plane.h"
|
||||
|
||||
namespace lin {
|
||||
|
||||
Plane Plane::TransformByIT(const Matrix4x4 &m, Plane *out) {
|
||||
void Plane::TransformByIT(const Matrix4x4 &m, Plane *out) {
|
||||
out->x = x * m.xx + y * m.yx + z * m.zx + d * m.wx;
|
||||
out->y = x * m.xy + y * m.yy + z * m.zy + d * m.wy;
|
||||
out->z = x * m.xz + y * m.yz + z * m.zz + d * m.wz;
|
||||
out->d = x * m.xw + y * m.yw + z * m.zw + d * m.ww;
|
||||
}
|
||||
|
||||
}
|
||||
+2
-6
@@ -3,8 +3,6 @@
|
||||
|
||||
#include "math/lin/vec3.h"
|
||||
|
||||
namespace lin {
|
||||
|
||||
class Matrix4x4;
|
||||
|
||||
class Plane {
|
||||
@@ -24,7 +22,7 @@ class Plane {
|
||||
}
|
||||
|
||||
void Normalize() {
|
||||
float inv_length = 1.0 * sqrtf(x * x + y * y + z * z);
|
||||
float inv_length = sqrtf(x * x + y * y + z * z);
|
||||
x *= inv_length;
|
||||
y *= inv_length;
|
||||
z *= inv_length;
|
||||
@@ -33,9 +31,7 @@ class Plane {
|
||||
|
||||
// Matrix is the inverse transpose of the wanted transform.
|
||||
// out cannot be equal to this.
|
||||
Plane TransformByIT(const Matrix4x4 &matrix, Plane *out);
|
||||
void TransformByIT(const Matrix4x4 &matrix, Plane *out);
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
+1
-7
@@ -1,10 +1,7 @@
|
||||
#ifndef _MATH_LIN_RAY_H
|
||||
#define _MATH_LIN_RAY_H
|
||||
#pragma once
|
||||
|
||||
#include "vec3.h"
|
||||
|
||||
namespace lin {
|
||||
|
||||
/* __declspec(align(16)) */ struct Ray
|
||||
{
|
||||
Vec3 origin;
|
||||
@@ -15,6 +12,3 @@ namespace lin {
|
||||
int pad3;
|
||||
};
|
||||
|
||||
} // namespace lin
|
||||
|
||||
#endif // _MATH_LIN_RAY_H
|
||||
@@ -22,6 +22,9 @@ public:
|
||||
Vec3() { }
|
||||
explicit Vec3(float f) {x=y=z=f;}
|
||||
|
||||
float operator [] (int i) const { return (&x)[i]; }
|
||||
float &operator [] (int i) { return (&x)[i]; }
|
||||
|
||||
Vec3(const float _x, const float _y, const float _z) {
|
||||
x=_x; y=_y; z=_z;
|
||||
}
|
||||
|
||||
+5
-2
@@ -1,8 +1,8 @@
|
||||
#ifndef _MATHUTILS_H
|
||||
#define _MATHUTILS_H
|
||||
|
||||
#include <math.h>
|
||||
#include <string.h>
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
|
||||
inline float sqr(float f) {return f*f;}
|
||||
inline float sqr_signed(float f) {return f<0 ? -f*f : f*f;}
|
||||
@@ -26,6 +26,9 @@ inline float Float16ToFloat(float16 ix) {
|
||||
|
||||
|
||||
#define PI 3.141592653589793f
|
||||
#ifndef M_PI
|
||||
#define M_PI 3.141592653589793f
|
||||
#endif
|
||||
|
||||
// The stuff in this file is from all over the web, esp. dspmusic.org. I think it's all public domain.
|
||||
// In any case, very little of it is used anywhere at the moment.
|
||||
|
||||
@@ -97,12 +97,15 @@
|
||||
<ClInclude Include="android\native_audio.h" />
|
||||
<ClInclude Include="audio\mixer.h" />
|
||||
<ClInclude Include="audio\wav_read.h" />
|
||||
<ClInclude Include="base\backtrace.h" />
|
||||
<ClInclude Include="base\basictypes.h" />
|
||||
<ClInclude Include="base\buffer.h" />
|
||||
<ClInclude Include="base\color.h" />
|
||||
<ClInclude Include="base\colorutil.h" />
|
||||
<ClInclude Include="base\display.h" />
|
||||
<ClInclude Include="base\error_context.h" />
|
||||
<ClInclude Include="base\fastlist.h" />
|
||||
<ClInclude Include="base\linked_ptr.h" />
|
||||
<ClInclude Include="base\logging.h" />
|
||||
<ClInclude Include="base\mutex.h" />
|
||||
<ClInclude Include="base\NativeApp.h" />
|
||||
@@ -140,7 +143,9 @@
|
||||
<ClInclude Include="input\input_state.h" />
|
||||
<ClInclude Include="json\json_writer.h" />
|
||||
<ClInclude Include="math\compression.h" />
|
||||
<ClInclude Include="math\lin\aabb.h" />
|
||||
<ClInclude Include="math\lin\matrix4x4.h" />
|
||||
<ClInclude Include="math\lin\plane.h" />
|
||||
<ClInclude Include="math\lin\quat.h" />
|
||||
<ClInclude Include="math\lin\vec3.h" />
|
||||
<ClInclude Include="math\math_util.h" />
|
||||
@@ -148,9 +153,12 @@
|
||||
<ClInclude Include="net\http_client.h" />
|
||||
<ClInclude Include="net\resolve.h" />
|
||||
<ClInclude Include="profiler\profiler.h" />
|
||||
<ClInclude Include="ui\list_screen.h" />
|
||||
<ClInclude Include="ui\screen.h" />
|
||||
<ClInclude Include="ui\ui.h" />
|
||||
<ClInclude Include="util\bits\bits.h" />
|
||||
<ClInclude Include="util\random\perlin.h" />
|
||||
<ClInclude Include="util\random\rng.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="android\app-android.cpp">
|
||||
@@ -167,6 +175,7 @@
|
||||
</ClCompile>
|
||||
<ClCompile Include="audio\mixer.cpp" />
|
||||
<ClCompile Include="audio\wav_read.cpp" />
|
||||
<ClCompile Include="base\backtrace.cpp" />
|
||||
<ClCompile Include="base\buffer.cpp" />
|
||||
<ClCompile Include="base\colorutil.cpp" />
|
||||
<ClCompile Include="base\display.cpp" />
|
||||
@@ -203,7 +212,9 @@
|
||||
<ClCompile Include="image\zim_save.cpp" />
|
||||
<ClCompile Include="input\gesture_detector.cpp" />
|
||||
<ClCompile Include="json\json_writer.cpp" />
|
||||
<ClCompile Include="math\lin\aabb.cpp" />
|
||||
<ClCompile Include="math\lin\matrix4x4.cpp" />
|
||||
<ClCompile Include="math\lin\plane.cpp" />
|
||||
<ClCompile Include="math\lin\quat.cpp" />
|
||||
<ClCompile Include="math\lin\vec3.cpp" />
|
||||
<ClCompile Include="math\math_util.cpp" />
|
||||
@@ -211,9 +222,11 @@
|
||||
<ClCompile Include="net\http_client.cpp" />
|
||||
<ClCompile Include="net\resolve.cpp" />
|
||||
<ClCompile Include="profiler\profiler.cpp" />
|
||||
<ClCompile Include="ui\list_screen.cpp" />
|
||||
<ClCompile Include="ui\screen.cpp" />
|
||||
<ClCompile Include="ui\ui.cpp" />
|
||||
<ClCompile Include="util\bits\bits.cpp" />
|
||||
<ClCompile Include="util\random\perlin.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
||||
@@ -184,6 +184,30 @@
|
||||
<ClInclude Include="ui\screen.h">
|
||||
<Filter>ui</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="base\linked_ptr.h">
|
||||
<Filter>base</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="ui\list_screen.h">
|
||||
<Filter>ui</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="base\backtrace.h">
|
||||
<Filter>base</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="base\fastlist.h">
|
||||
<Filter>base</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="math\lin\aabb.h">
|
||||
<Filter>math</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="math\lin\plane.h">
|
||||
<Filter>math</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="util\random\perlin.h">
|
||||
<Filter>util</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="util\random\rng.h">
|
||||
<Filter>util</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="gfx\gl_debug_log.cpp">
|
||||
@@ -333,6 +357,21 @@
|
||||
<ClCompile Include="ui\screen.cpp">
|
||||
<Filter>ui</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="ui\list_screen.cpp">
|
||||
<Filter>ui</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="base\backtrace.cpp">
|
||||
<Filter>base</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="math\lin\aabb.cpp">
|
||||
<Filter>math</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="math\lin\plane.cpp">
|
||||
<Filter>math</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="util\random\perlin.cpp">
|
||||
<Filter>util</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Filter Include="gfx">
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
#include "ui/list_screen.h"
|
||||
|
||||
ListScreen::ListScreen() {
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
#include "ui/screen.h"
|
||||
|
||||
|
||||
class ListScreen {
|
||||
public:
|
||||
ListScreen();
|
||||
|
||||
private:
|
||||
|
||||
};
|
||||
+1
-1
@@ -56,7 +56,7 @@ private:
|
||||
Screen *currentScreen_;
|
||||
Screen *nextScreen_;
|
||||
|
||||
// Dialog stack. These are shown "on top" of base screens and back works as expected.
|
||||
// Dialog stack. These are shown "on top" of base screens and the Android back button works as expected.
|
||||
// Used for options, in-game menus and other things you expect to be able to back out from onto something.
|
||||
std::list<Screen *> dialog_;
|
||||
};
|
||||
|
||||
@@ -10,6 +10,8 @@
|
||||
// TODO: UI should probably not own these.
|
||||
DrawBuffer ui_draw2d;
|
||||
DrawBuffer ui_draw2d_front;
|
||||
|
||||
// This one, though, is OK.
|
||||
UIState uistate;
|
||||
|
||||
// Theme.
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
// A common pattern is Adapter classes for changing how things are drawn
|
||||
// in lists, for example.
|
||||
//
|
||||
// Immediate UI works great for overlay UI for games, for example, but is actually
|
||||
// not really a good idea for full app UIs. Also, animations are difficult because
|
||||
// there's not really any good place to store state.
|
||||
//
|
||||
// hrydgard@gmail.com
|
||||
|
||||
#pragma once
|
||||
|
||||
@@ -47,14 +47,14 @@ inline float grad(int hash, float x, float y, float z) {
|
||||
return ((h & 1) == 0 ? u : -u) + ((h & 2) == 0 ? v : -v);
|
||||
}
|
||||
|
||||
float Noise(double z, double y, double x) {
|
||||
double fx = floor(x), fy = floor(y), fz = floor(z);
|
||||
float Noise(double iz, double iy, double ix) {
|
||||
double fx = floor(ix), fy = floor(iy), fz = floor(iz);
|
||||
int X = (int)fx & 255, // FIND UNIT CUBE THAT
|
||||
Y = (int)fy & 255, // CONTAINS POINT.
|
||||
Z = (int)fz & 255;
|
||||
x -= fx; // FIND RELATIVE X,Y,Z
|
||||
y -= fy; // OF POINT IN CUBE.
|
||||
z -= fz;
|
||||
float x = (float)(ix - fx); // FIND RELATIVE X,Y,Z
|
||||
float y = (float)(iy - fy); // OF POINT IN CUBE.
|
||||
float z = (float)(iz - fz);
|
||||
float u = fade(x); // COMPUTE FADE CURVES
|
||||
float v = fade(y); // FOR EACH OF X,Y,Z.
|
||||
float w = fade(z);
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
#ifndef _PERLIN_H
|
||||
#define _PERLIN_H
|
||||
#pragma once
|
||||
|
||||
// Implementation of "Improved Noise"
|
||||
// http://mrl.nyu.edu/~perlin/noise/
|
||||
// doubles are only used at the very start, not a big performance worry
|
||||
float Noise(double x, double y, double z);
|
||||
|
||||
#endif // _PERLIN_H
|
||||
+1
-4
@@ -1,5 +1,4 @@
|
||||
#ifndef _RNG_H
|
||||
#define _RNG_H
|
||||
#pragma once
|
||||
|
||||
#include "base/basictypes.h"
|
||||
|
||||
@@ -22,5 +21,3 @@ class GMRng {
|
||||
uint32 m_w;
|
||||
uint32 m_z;
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user