Updated Source Generation Tools
This commit is contained in:
File diff suppressed because it is too large
Load Diff
2521
rcbasic_build/rc_builtin2.h
Normal file
2521
rcbasic_build/rc_builtin2.h
Normal file
File diff suppressed because it is too large
Load Diff
@@ -69,4 +69,19 @@ bool is_file_exist(const char *fileName)
|
||||
return infile.good();
|
||||
}
|
||||
|
||||
std::string rc_replace(std::string src, std::string tgt, std::string rpc)
|
||||
{
|
||||
if(tgt.length()==0)
|
||||
return src;
|
||||
size_t found_inc = rpc.length() > 0 ? rpc.length() : 1;
|
||||
size_t found = 0;
|
||||
found = src.find(tgt);
|
||||
while( found != string::npos && found < src.length())
|
||||
{
|
||||
src = src.substr(0,found) + rpc + src.substr(found + tgt.length());
|
||||
found = src.find(tgt,found+found_inc);
|
||||
}
|
||||
return src;
|
||||
}
|
||||
|
||||
#endif // RC_UTILITY_H_INCLUDED
|
||||
|
||||
Binary file not shown.
258
rcbasic_runtime/camera.h
Normal file
258
rcbasic_runtime/camera.h
Normal file
@@ -0,0 +1,258 @@
|
||||
#ifndef CAMERA_H_INCLUDED
|
||||
#define CAMERA_H_INCLUDED
|
||||
|
||||
|
||||
#include <irrlicht.h>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
// use all irrlicht namespaces
|
||||
using namespace irr;
|
||||
|
||||
using namespace core;
|
||||
using namespace scene;
|
||||
using namespace video;
|
||||
using namespace io;
|
||||
using namespace gui;
|
||||
|
||||
|
||||
/*
|
||||
==========
|
||||
rotateNode -- rotate a scene node locally
|
||||
==========
|
||||
*/
|
||||
void rotateNode(irr::scene::ISceneNode *node, irr::core::vector3df rot)
|
||||
{
|
||||
irr::core::matrix4 m;
|
||||
m.setRotationDegrees(node->getRotation());
|
||||
irr::core::matrix4 n;
|
||||
n.setRotationDegrees(rot);
|
||||
m *= n;
|
||||
node->setRotation( m.getRotationDegrees() );
|
||||
node->updateAbsolutePosition();
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
==========
|
||||
translateNode -- translate a scene node locally
|
||||
==========
|
||||
*/
|
||||
void translateNode(ISceneNode *node, vector3df vel)
|
||||
{
|
||||
irr::core::matrix4 m;
|
||||
m.setRotationDegrees(node->getRotation());
|
||||
m.transformVect(vel);
|
||||
node->setPosition(node->getPosition() + vel);
|
||||
node->updateAbsolutePosition();
|
||||
}
|
||||
|
||||
void translateNodeW(ISceneNode *node, vector3df vel)
|
||||
{
|
||||
node->setPosition(node->getPosition() + vel);
|
||||
node->updateAbsolutePosition();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* camera framework */
|
||||
class Camera
|
||||
{
|
||||
public:
|
||||
|
||||
irr::scene::ISceneManager* Scene;
|
||||
|
||||
irr::scene::ICameraSceneNode *camera; // the actual camera
|
||||
ISceneNode *top; // above camera
|
||||
ISceneNode *front; // in front of camera
|
||||
|
||||
f32 rx,ry,rz;
|
||||
f32 x,y,z;
|
||||
|
||||
vector3df direction;
|
||||
|
||||
|
||||
// initialize a camera at 0,0,0 or the location passed in
|
||||
void init(irr::scene::ISceneManager* smgr, float x=0, float y=0, float z=0);
|
||||
|
||||
void re_init();
|
||||
|
||||
|
||||
// locally translate the camera
|
||||
void translate(float x, float y, float z);
|
||||
void translateW(float x, float y, float z);
|
||||
|
||||
|
||||
// locally rotate the camera
|
||||
void rotate(float x, float y, float z);
|
||||
|
||||
// update the camera, should be called at the end of mainloop
|
||||
void update(void);
|
||||
|
||||
// sets the global rotation of the camera
|
||||
void setRotation(float x, float y, float z);
|
||||
|
||||
// sets the global position of the camera
|
||||
void setPosition(float x, float y, float z);
|
||||
|
||||
// gets the global position of camera
|
||||
void getPosition(f32 &x, f32 &y, f32 &z);
|
||||
};
|
||||
|
||||
|
||||
// initialize a camera at 0,0,0 or the location passed in
|
||||
void Camera::init(irr::scene::ISceneManager* smgr, float x, float y, float z)
|
||||
{
|
||||
Scene = smgr;
|
||||
|
||||
// create camera scene node
|
||||
camera = Scene->addCameraSceneNode(NULL, vector3df(x,y,z));
|
||||
|
||||
// empty reference nodes
|
||||
top = Scene->addEmptySceneNode();
|
||||
front = Scene->addEmptySceneNode();
|
||||
|
||||
// parent the reference nodes
|
||||
camera->addChild(top);
|
||||
camera->addChild(front);
|
||||
|
||||
// put the reference nodes in place
|
||||
front->setPosition(vector3df(0,0,1));
|
||||
top->setPosition(vector3df(0,1,0));
|
||||
|
||||
// set lookat
|
||||
camera->setUpVector(top->getAbsolutePosition() - camera->getAbsolutePosition());
|
||||
camera->setTarget(front->getAbsolutePosition() - camera->getAbsolutePosition());
|
||||
|
||||
direction = vector3df(0,0,1);
|
||||
|
||||
//camera = Scene->addCameraSceneNodeFPS();
|
||||
|
||||
rx=ry=rz=0;
|
||||
x=y=z=0;
|
||||
}
|
||||
|
||||
|
||||
// initialize a camera at 0,0,0 or the location passed in
|
||||
void Camera::re_init()
|
||||
{
|
||||
|
||||
//Scene = smgr;
|
||||
|
||||
// create camera scene node
|
||||
//camera = Scene->addCameraSceneNode(NULL, vector3df(x,y,z));
|
||||
|
||||
// empty reference nodes
|
||||
//top = Scene->addEmptySceneNode();
|
||||
//front = Scene->addEmptySceneNode();
|
||||
|
||||
// parent the reference nodes
|
||||
//camera->addChild(top);
|
||||
//camera->addChild(front);
|
||||
|
||||
// put the reference nodes in place
|
||||
front->setPosition(vector3df(0,0,1));
|
||||
top->setPosition(vector3df(0,1,0));
|
||||
|
||||
// set lookat
|
||||
camera->setUpVector(top->getAbsolutePosition() - camera->getAbsolutePosition());
|
||||
camera->setTarget(front->getAbsolutePosition() - camera->getAbsolutePosition());
|
||||
|
||||
direction = vector3df(0,0,1);
|
||||
|
||||
//camera = Scene->addCameraSceneNodeFPS();
|
||||
|
||||
rx=ry=rz=0;
|
||||
x=y=z=0;
|
||||
}
|
||||
|
||||
// locally translate the camera
|
||||
void Camera::translate(float x, float y, float z)
|
||||
{
|
||||
// translate the camera locally
|
||||
translateNode(camera, vector3df(x,y,z));
|
||||
|
||||
// update reference nodes
|
||||
front->updateAbsolutePosition();
|
||||
top->updateAbsolutePosition();
|
||||
}
|
||||
|
||||
// locally translate the camera
|
||||
void Camera::translateW(float x, float y, float z)
|
||||
{
|
||||
// translate the camera locally
|
||||
translateNodeW(camera, vector3df(x,y,z));
|
||||
|
||||
// update reference nodes
|
||||
front->updateAbsolutePosition();
|
||||
top->updateAbsolutePosition();
|
||||
}
|
||||
|
||||
// locally rotate the camera
|
||||
void Camera::rotate(float x, float y, float z)
|
||||
{
|
||||
rotateNode(camera, vector3df(x, y, z));
|
||||
|
||||
rx += x;
|
||||
ry += y;
|
||||
rz += z;
|
||||
}
|
||||
|
||||
// update the camera, should be called at the end of mainloop
|
||||
void Camera::update(void)
|
||||
{
|
||||
camera->updateAbsolutePosition();
|
||||
|
||||
camera->setTarget(front->getAbsolutePosition());
|
||||
camera->setUpVector(top->getAbsolutePosition() - camera->getAbsolutePosition());
|
||||
|
||||
vector3df pos;
|
||||
pos = camera->getAbsolutePosition();
|
||||
x=pos.X;
|
||||
y=pos.Y;
|
||||
z=pos.Z;
|
||||
|
||||
pos = camera->getRotation();
|
||||
|
||||
//rx=pos.X;
|
||||
//ry=pos.Y;
|
||||
//rz=pos.Z;
|
||||
}
|
||||
|
||||
// sets the global rotation of the camera
|
||||
void Camera::setRotation(float x, float y, float z)
|
||||
{
|
||||
camera->setRotation(vector3df(x,y,z));
|
||||
camera->updateAbsolutePosition();
|
||||
|
||||
front->updateAbsolutePosition();
|
||||
top->updateAbsolutePosition();
|
||||
|
||||
rx=x;
|
||||
ry=y;
|
||||
rz=z;
|
||||
}
|
||||
|
||||
// sets the global position of the camera
|
||||
void Camera::setPosition(float x, float y, float z)
|
||||
{
|
||||
camera->setPosition(vector3df(x,y,z));
|
||||
camera->updateAbsolutePosition();
|
||||
|
||||
front->updateAbsolutePosition();
|
||||
top->updateAbsolutePosition();
|
||||
}
|
||||
|
||||
// gets the global position of camera
|
||||
void Camera::getPosition(f32 &x, f32 &y, f32 &z)
|
||||
{
|
||||
vector3df pos;
|
||||
pos = camera->getAbsolutePosition();
|
||||
|
||||
x=pos.X;
|
||||
y=pos.Y;
|
||||
z=pos.Z;
|
||||
}
|
||||
|
||||
|
||||
#endif // CAMERA_H_INCLUDED
|
||||
538
rcbasic_runtime/gui_freetype_font.cpp
Normal file
538
rcbasic_runtime/gui_freetype_font.cpp
Normal file
@@ -0,0 +1,538 @@
|
||||
#include "gui_freetype_font.h"
|
||||
|
||||
#if COMPILE_WITH_FREETYPE
|
||||
|
||||
#include <cassert>
|
||||
|
||||
using namespace irr;
|
||||
using namespace gui;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(disable: 4996)
|
||||
#endif
|
||||
|
||||
|
||||
// --------------------------------------------------------
|
||||
CGUITTGlyph::CGUITTGlyph()
|
||||
: IReferenceCounted()
|
||||
,cached(false)
|
||||
,size(0)
|
||||
,top(0)
|
||||
,left(0)
|
||||
,texw(0)
|
||||
,texh(0)
|
||||
,imgw(0)
|
||||
,imgh(0)
|
||||
,tex(NULL)
|
||||
,top16(0)
|
||||
,left16(0)
|
||||
,texw16(0)
|
||||
,texh16(0)
|
||||
,imgw16(0)
|
||||
,imgh16(0)
|
||||
,tex16(NULL)
|
||||
,image(NULL)
|
||||
{
|
||||
}
|
||||
|
||||
CGUITTGlyph::~CGUITTGlyph()
|
||||
{
|
||||
delete[] image;
|
||||
}
|
||||
|
||||
//void CGUITTGlyph::cache(u32 idx_, CGUITTFace& ttFace_, video::IVideoDriver* driver_, irr::core::dimension2d<irr::u32> &largestSize)
|
||||
void CGUITTGlyph::cache(u32 idx_, const CGUIFreetypeFont * freetypeFont)
|
||||
{
|
||||
assert(freetypeFont);
|
||||
|
||||
FT_Face face = freetypeFont->TrueTypeFace->face;
|
||||
|
||||
FT_Set_Pixel_Sizes(face, 0, size);
|
||||
if ( size > freetypeFont->LargestGlyph.Height )
|
||||
freetypeFont->LargestGlyph.Height = size;
|
||||
|
||||
if ( !FT_Load_Glyph(face, idx_, FT_LOAD_NO_HINTING|FT_LOAD_NO_BITMAP) )
|
||||
{
|
||||
FT_GlyphSlot glyph = face->glyph;
|
||||
FT_Bitmap bits;
|
||||
|
||||
if (glyph->format == ft_glyph_format_outline )
|
||||
{
|
||||
if (!FT_Render_Glyph( glyph, FT_RENDER_MODE_NORMAL))
|
||||
{
|
||||
bits = glyph->bitmap;
|
||||
u8 *pt = bits.buffer;
|
||||
delete[] image;
|
||||
image = new u8[bits.width * bits.rows];
|
||||
memcpy(image,pt,bits.width * bits.rows);
|
||||
top = glyph->bitmap_top;
|
||||
left = glyph->bitmap_left;
|
||||
imgw = 1;
|
||||
imgh = 1;
|
||||
texw = bits.width;
|
||||
texh = bits.rows;
|
||||
for(;;)
|
||||
{
|
||||
if (imgw > texw)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
imgw <<= 1;
|
||||
}
|
||||
}
|
||||
for(;;)
|
||||
{
|
||||
if (imgh > texh)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
imgh <<= 1;
|
||||
}
|
||||
}
|
||||
if (imgw > imgh)
|
||||
{
|
||||
imgh = imgw;
|
||||
}
|
||||
else
|
||||
{
|
||||
imgw = imgh;
|
||||
}
|
||||
|
||||
s32 offx = left;
|
||||
s32 offy = size - top;
|
||||
if ( offx+texw > freetypeFont->LargestGlyph.Width )
|
||||
freetypeFont->LargestGlyph.Width = offx+texw;
|
||||
if ( offy+texh > freetypeFont->LargestGlyph.Height )
|
||||
freetypeFont->LargestGlyph.Height = offy+texh;
|
||||
|
||||
u32 *texd = new u32[imgw*imgh];
|
||||
memset(texd,0,imgw*imgh*sizeof(u32));
|
||||
u32 *texp = texd;
|
||||
bool cflag = (freetypeFont->Driver->getDriverType() == video::EDT_DIRECT3D9);
|
||||
for (int i = 0;i < bits.rows;i++)
|
||||
{
|
||||
u32 *rowp = texp;
|
||||
for (int j = 0;j < bits.width;j++)
|
||||
{
|
||||
if (*pt)
|
||||
{
|
||||
if (cflag)
|
||||
{
|
||||
*rowp = *pt;
|
||||
*rowp *= 0x01010101;
|
||||
}
|
||||
else
|
||||
{
|
||||
*rowp = *pt << 24;
|
||||
*rowp |= 0xffffff;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*rowp = 0;
|
||||
}
|
||||
pt++;
|
||||
rowp++;
|
||||
}
|
||||
texp += imgw;
|
||||
}
|
||||
|
||||
c8 name[128];
|
||||
sprintf(name,"ttf%d_%d_%p",idx_, size, freetypeFont );
|
||||
video::IImage *img = freetypeFont->Driver->createImageFromData(video::ECF_A8R8G8B8,core::dimension2d<u32>(imgw,imgh),texd);
|
||||
setGlyphTextureFlags(freetypeFont->Driver);
|
||||
tex = freetypeFont->Driver->addTexture(name,img);
|
||||
img->drop();
|
||||
restoreTextureFlags(freetypeFont->Driver);
|
||||
delete[] texd;
|
||||
cached = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!FT_Load_Glyph(face,idx_,FT_LOAD_NO_HINTING|FT_LOAD_RENDER|FT_LOAD_MONOCHROME))
|
||||
{
|
||||
FT_GlyphSlot glyph = face->glyph;
|
||||
FT_Bitmap bits = glyph->bitmap;
|
||||
u8 *pt = bits.buffer;
|
||||
top16 = glyph->bitmap_top;
|
||||
left16 = glyph->bitmap_left;
|
||||
imgw16 = 1;
|
||||
imgh16 = 1;
|
||||
texw16 = bits.width;
|
||||
texh16 = bits.rows;
|
||||
for(;;)
|
||||
{
|
||||
if (imgw16 >= texw16)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
imgw16 <<= 1;
|
||||
}
|
||||
}
|
||||
for(;;)
|
||||
{
|
||||
if (imgh16 >= texh16)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
imgh16 <<= 1;
|
||||
}
|
||||
}
|
||||
if (imgw16 > imgh16)
|
||||
{
|
||||
imgh16 = imgw16;
|
||||
}
|
||||
else
|
||||
{
|
||||
imgw16 = imgh16;
|
||||
}
|
||||
|
||||
s32 offx = left;
|
||||
s32 offy = size - top;
|
||||
if ( offx+texw > freetypeFont->LargestGlyph.Width )
|
||||
freetypeFont->LargestGlyph.Width = offx+texw;
|
||||
if ( offy+texh > freetypeFont->LargestGlyph.Height )
|
||||
freetypeFont->LargestGlyph.Height = offy+texh;
|
||||
|
||||
|
||||
u16 *texd16 = new u16[imgw16*imgh16];
|
||||
memset(texd16,0,imgw16*imgh16*sizeof(u16));
|
||||
u16 *texp16 = texd16;
|
||||
for (int y = 0;y < bits.rows;y++)
|
||||
{
|
||||
u16 *rowp = texp16;
|
||||
for (int x = 0;x < bits.width;x++)
|
||||
{
|
||||
if (pt[y * bits.pitch + (x / 8)] & (0x80 >> (x % 8)))
|
||||
{
|
||||
*rowp = 0xffff;
|
||||
}
|
||||
rowp++;
|
||||
}
|
||||
texp16 += imgw16;
|
||||
}
|
||||
c8 name[128];
|
||||
sprintf(name,"ttf%d_%d_%p_16",idx_, size, freetypeFont );
|
||||
video::IImage *img = freetypeFont->Driver->createImageFromData(video::ECF_A1R5G5B5,core::dimension2d<u32>(imgw16,imgh16),texd16);
|
||||
setGlyphTextureFlags(freetypeFont->Driver);
|
||||
tex16 = freetypeFont->Driver->addTexture(name,img);
|
||||
img->drop();
|
||||
restoreTextureFlags(freetypeFont->Driver);
|
||||
// freetypeFont->Driver->makeColorKeyTexture(tex16,video::SColor(0,0,0,0));
|
||||
delete[] texd16;
|
||||
}
|
||||
}
|
||||
|
||||
bool CGUITTGlyph::mTexFlag16 = false;
|
||||
bool CGUITTGlyph::mTexFlag32 = true;
|
||||
bool CGUITTGlyph::mTexFlagMip = false;
|
||||
|
||||
void CGUITTGlyph::setGlyphTextureFlags(video::IVideoDriver* driver_)
|
||||
{
|
||||
mTexFlag16 = driver_->getTextureCreationFlag(video::ETCF_ALWAYS_16_BIT);
|
||||
mTexFlag32 = driver_->getTextureCreationFlag(video::ETCF_ALWAYS_32_BIT);
|
||||
mTexFlagMip = driver_->getTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS);
|
||||
driver_->setTextureCreationFlag(video::ETCF_ALWAYS_16_BIT,false);
|
||||
driver_->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT,true);
|
||||
driver_->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, false);
|
||||
}
|
||||
|
||||
void CGUITTGlyph::restoreTextureFlags(video::IVideoDriver* driver_)
|
||||
{
|
||||
driver_->setTextureCreationFlag(video::ETCF_ALWAYS_16_BIT, mTexFlag16);
|
||||
driver_->setTextureCreationFlag(video::ETCF_ALWAYS_32_BIT, mTexFlag32);
|
||||
driver_->setTextureCreationFlag(video::ETCF_CREATE_MIP_MAPS, mTexFlagMip);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
FT_Library CGUITTFace::library = 0;
|
||||
int CGUITTFace::countClassObjects = 0;
|
||||
|
||||
CGUITTFace::CGUITTFace()
|
||||
: face(0)
|
||||
{
|
||||
++countClassObjects;
|
||||
}
|
||||
|
||||
CGUITTFace::~CGUITTFace()
|
||||
{
|
||||
if ( face )
|
||||
FT_Done_Face( face );
|
||||
|
||||
--countClassObjects;
|
||||
assert(countClassObjects >= 0 );
|
||||
if ( !countClassObjects && library )
|
||||
{
|
||||
FT_Done_FreeType( library );
|
||||
library = 0;
|
||||
}
|
||||
}
|
||||
|
||||
//! loads a font file
|
||||
bool CGUITTFace::load(const irr::io::path& filename)
|
||||
{
|
||||
if ( !library )
|
||||
{
|
||||
if (FT_Init_FreeType( &library ))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
core::stringc ansiFilename(filename); // path can be anything but freetype can only work with ansi-filenames
|
||||
if (FT_New_Face( library,ansiFilename.c_str(),0,&face ))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
//! constructor
|
||||
CGUIFreetypeFont::CGUIFreetypeFont(video::IVideoDriver* driver)
|
||||
: Driver(driver)
|
||||
, TrueTypeFace(0)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("CGUIFreetypeFont");
|
||||
#endif
|
||||
|
||||
if (Driver)
|
||||
Driver->grab();
|
||||
AntiAlias = false;
|
||||
Transparency = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//! destructor
|
||||
CGUIFreetypeFont::~CGUIFreetypeFont()
|
||||
{
|
||||
if ( TrueTypeFace )
|
||||
TrueTypeFace->drop();
|
||||
if (Driver)
|
||||
Driver->drop();
|
||||
clearGlyphs();
|
||||
}
|
||||
|
||||
bool CGUIFreetypeFont::attach(CGUITTFace *Face,u32 size)
|
||||
{
|
||||
if (!Driver || !Face)
|
||||
return false;
|
||||
|
||||
Face->grab();
|
||||
if ( TrueTypeFace )
|
||||
TrueTypeFace->drop();
|
||||
TrueTypeFace = Face;
|
||||
if ( !TrueTypeFace )
|
||||
return false;
|
||||
|
||||
clearGlyphs();
|
||||
Glyphs.reallocate(TrueTypeFace->face->num_glyphs);
|
||||
Glyphs.set_used(TrueTypeFace->face->num_glyphs);
|
||||
for (int i = 0;i < TrueTypeFace->face->num_glyphs;i++)
|
||||
{
|
||||
CGUITTGlyph * glyph = new CGUITTGlyph();
|
||||
|
||||
glyph->size = size;
|
||||
// glyph->cache((wchar_t)i + 1);
|
||||
|
||||
Glyphs[i] = glyph;
|
||||
}
|
||||
|
||||
// TODO: this is a workaround to get a probably ok height for getDimensions. So we check a few extreme characters which usually make trouble.
|
||||
getGlyphByChar(L'A');
|
||||
getGlyphByChar(L'g');
|
||||
getGlyphByChar(L'.');
|
||||
getGlyphByChar(L'(');
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void CGUIFreetypeFont::clearGlyphs()
|
||||
{
|
||||
for ( unsigned int i=0; i < Glyphs.size(); ++i )
|
||||
{
|
||||
if ( Glyphs[i] )
|
||||
{
|
||||
Glyphs[i]->drop();
|
||||
}
|
||||
Glyphs[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
u32 CGUIFreetypeFont::getGlyphByChar(wchar_t c) const
|
||||
{
|
||||
u32 idx = FT_Get_Char_Index( TrueTypeFace->face, c );
|
||||
if ( idx && !Glyphs[idx - 1]->cached )
|
||||
Glyphs[idx - 1]->cache(idx, this);
|
||||
return idx;
|
||||
}
|
||||
|
||||
//! returns the dimension of a text
|
||||
core::dimension2d<u32> CGUIFreetypeFont::getDimension(const wchar_t* text) const
|
||||
{
|
||||
core::dimension2d<u32> dim(0, Glyphs[0]->size);
|
||||
|
||||
for(const wchar_t* p = text; *p; ++p)
|
||||
{
|
||||
dim.Width += getWidthFromCharacter(*p);
|
||||
}
|
||||
|
||||
// TODO: The correct solution might be working with TrueTypeFace->height but I can't figure out how to use units_per_EM
|
||||
// even if I know which FT_Render_Mode I used. I'm sure there is some way to figure that out, but I have to give up for now.
|
||||
if ( TrueTypeFace && LargestGlyph.Height > dim.Height)
|
||||
dim.Height = LargestGlyph.Height;
|
||||
|
||||
return dim;
|
||||
}
|
||||
|
||||
|
||||
inline u32 CGUIFreetypeFont::getWidthFromCharacter(wchar_t c) const
|
||||
{
|
||||
u32 n = getGlyphByChar(c);
|
||||
if ( n > 0)
|
||||
{
|
||||
int w = Glyphs[n - 1]->texw;
|
||||
s32 left = Glyphs[n - 1]->left;
|
||||
if (w + left > 0)
|
||||
return w + left;
|
||||
}
|
||||
if (c >= 0x2000)
|
||||
{
|
||||
return Glyphs[0]->size;
|
||||
}
|
||||
else
|
||||
{
|
||||
return Glyphs[0]->size / 2;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! draws an text and clips it to the specified rectangle if wanted
|
||||
void CGUIFreetypeFont::draw(const irr::core::stringw& textstring, const irr::core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip)
|
||||
{
|
||||
if (!Driver)
|
||||
return;
|
||||
|
||||
core::dimension2d<s32> textDimension;
|
||||
core::position2d<s32> offset = position.UpperLeftCorner;
|
||||
video::SColor colors[4];
|
||||
for (int i = 0;i < 4;i++)
|
||||
{
|
||||
colors[i] = color;
|
||||
}
|
||||
|
||||
const wchar_t * text = textstring.c_str();
|
||||
if (hcenter || vcenter)
|
||||
{
|
||||
textDimension = getDimension(text);
|
||||
|
||||
if (hcenter)
|
||||
offset.X = ((position.getWidth() - textDimension.Width)>>1) + offset.X;
|
||||
|
||||
if (vcenter)
|
||||
offset.Y = ((position.getHeight() - textDimension.Height)>>1) + offset.Y;
|
||||
}
|
||||
|
||||
u32 n;
|
||||
|
||||
while(*text)
|
||||
{
|
||||
n = getGlyphByChar(*text);
|
||||
if ( n > 0)
|
||||
{
|
||||
if (AntiAlias)
|
||||
{
|
||||
// s32 imgw = Glyphs[n-1]->imgw;
|
||||
// s32 imgh = Glyphs[n-1]->imgh;
|
||||
s32 texw = Glyphs[n-1]->texw;
|
||||
s32 texh = Glyphs[n-1]->texh;
|
||||
s32 offx = Glyphs[n-1]->left;
|
||||
s32 offy = Glyphs[n-1]->size - Glyphs[n-1]->top;
|
||||
if (Driver->getDriverType() != video::EDT_SOFTWARE)
|
||||
{
|
||||
if (!Transparency)
|
||||
color.color |= 0xff000000;
|
||||
Driver->draw2DImage(Glyphs[n-1]->tex,core::position2d<s32>(offset.X+offx,offset.Y+offy),core::rect<s32>(0,0,texw,texh),clip,color,true);
|
||||
}
|
||||
else
|
||||
{
|
||||
s32 a = color.getAlpha();
|
||||
s32 r = color.getRed();
|
||||
s32 g = color.getGreen();
|
||||
s32 b = color.getBlue();
|
||||
u8 *pt = Glyphs[n-1]->image;
|
||||
if (!Transparency) a = 255;
|
||||
for (int y = 0;y < texh;y++)
|
||||
{
|
||||
for (int x = 0;x < texw;x++)
|
||||
{
|
||||
if (!clip || clip->isPointInside(core::position2d<s32>(offset.X+x+offx,offset.Y+y+offy)))
|
||||
{
|
||||
if (*pt)
|
||||
{
|
||||
Driver->draw2DRectangle(video::SColor((a * *pt)/255,r,g,b),core::rect<s32>(offset.X+x+offx,offset.Y+y+offy,offset.X+x+offx+1,offset.Y+y+offy+1));
|
||||
}
|
||||
pt++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// s32 imgw = Glyphs[n-1]->imgw16;
|
||||
// s32 imgh = Glyphs[n-1]->imgh16;
|
||||
s32 texw = Glyphs[n-1]->texw16;
|
||||
s32 texh = Glyphs[n-1]->texh16;
|
||||
s32 offx = Glyphs[n-1]->left16;
|
||||
s32 offy = Glyphs[n-1]->size - Glyphs[n-1]->top16;
|
||||
if (!Transparency)
|
||||
{
|
||||
color.color |= 0xff000000;
|
||||
}
|
||||
Driver->draw2DImage(Glyphs[n-1]->tex16,
|
||||
core::position2d<s32>(offset.X+offx,offset.Y+offy),
|
||||
core::rect<s32>(0,0,texw,texh),
|
||||
clip, color, true);
|
||||
}
|
||||
offset.X += getWidthFromCharacter(*text);
|
||||
}
|
||||
else
|
||||
{
|
||||
offset.X += getWidthFromCharacter(*text);
|
||||
}
|
||||
|
||||
++text;
|
||||
}
|
||||
}
|
||||
|
||||
//! Calculates the index of the character in the text which is on a specific position.
|
||||
s32 CGUIFreetypeFont::getCharacterFromPos(const wchar_t* text, s32 pixel_x) const
|
||||
{
|
||||
s32 x = 0;
|
||||
s32 idx = 0;
|
||||
|
||||
while (text[idx])
|
||||
{
|
||||
x += getWidthFromCharacter(text[idx]);
|
||||
|
||||
if (x >= pixel_x)
|
||||
return idx;
|
||||
|
||||
++idx;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
#endif // #if COMPILE_WITH_FREETYPE
|
||||
124
rcbasic_runtime/gui_freetype_font.h
Normal file
124
rcbasic_runtime/gui_freetype_font.h
Normal file
@@ -0,0 +1,124 @@
|
||||
#ifndef _GUI_FREETYPE_FONT_H
|
||||
#define _GUI_FREETYPE_FONT_H
|
||||
|
||||
//! freetype support enabled with 1 and disabled with 0
|
||||
#define COMPILE_WITH_FREETYPE 1
|
||||
|
||||
|
||||
#if COMPILE_WITH_FREETYPE
|
||||
|
||||
#include <freetype2/ft2build.h>
|
||||
#include <freetype/freetype.h>
|
||||
#include <irrlicht.h>
|
||||
|
||||
class CGUITTFace : public irr::IReferenceCounted
|
||||
{
|
||||
public:
|
||||
CGUITTFace();
|
||||
virtual ~CGUITTFace();
|
||||
|
||||
bool load(const irr::io::path& filename);
|
||||
|
||||
FT_Face face; // handle to face
|
||||
|
||||
private:
|
||||
static int countClassObjects;
|
||||
static FT_Library library; // handle to library
|
||||
};
|
||||
|
||||
class CGUIFreetypeFont;
|
||||
|
||||
class CGUITTGlyph : public irr::IReferenceCounted
|
||||
{
|
||||
public:
|
||||
CGUITTGlyph();
|
||||
virtual ~CGUITTGlyph();
|
||||
|
||||
bool cached;
|
||||
void cache(irr::u32 idx_, const CGUIFreetypeFont * freetypeFont);
|
||||
|
||||
irr::u32 size;
|
||||
irr::u32 top;
|
||||
irr::u32 left;
|
||||
irr::u32 texw;
|
||||
irr::u32 texh;
|
||||
irr::u32 imgw;
|
||||
irr::u32 imgh;
|
||||
irr::video::ITexture *tex;
|
||||
irr::u32 top16;
|
||||
irr::u32 left16;
|
||||
irr::u32 texw16;
|
||||
irr::u32 texh16;
|
||||
irr::u32 imgw16;
|
||||
irr::u32 imgh16;
|
||||
irr::video::ITexture *tex16;
|
||||
irr::u8 *image;
|
||||
|
||||
private:
|
||||
void setGlyphTextureFlags(irr::video::IVideoDriver* driver_);
|
||||
void restoreTextureFlags(irr::video::IVideoDriver* driver_);
|
||||
|
||||
static bool mTexFlag16;
|
||||
static bool mTexFlag32;
|
||||
static bool mTexFlagMip;
|
||||
};
|
||||
|
||||
class CGUIFreetypeFont : public irr::gui::IGUIFont
|
||||
{
|
||||
friend class CGUITTGlyph;
|
||||
|
||||
public:
|
||||
|
||||
//! constructor
|
||||
CGUIFreetypeFont(irr::video::IVideoDriver* Driver);
|
||||
|
||||
//! destructor
|
||||
virtual ~CGUIFreetypeFont();
|
||||
|
||||
//! loads a truetype font file
|
||||
bool attach(CGUITTFace *Face,irr::u32 size);
|
||||
|
||||
//! draws an text and clips it to the specified rectangle if wanted
|
||||
virtual void draw(const irr::core::stringw& text, const irr::core::rect<irr::s32>& position, irr::video::SColor color, bool hcenter=false, bool vcenter=false, const irr::core::rect<irr::s32>* clip=0);
|
||||
|
||||
//! returns the dimension of a text
|
||||
virtual irr::core::dimension2d<irr::u32> getDimension(const wchar_t* text) const;
|
||||
|
||||
//! Calculates the index of the character in the text which is on a specific position.
|
||||
virtual irr::s32 getCharacterFromPos(const wchar_t* text, irr::s32 pixel_x) const;
|
||||
|
||||
//! Not yet supported
|
||||
virtual void setKerningWidth (irr::s32 kerning) {}
|
||||
|
||||
//! Not yet supported
|
||||
virtual void setKerningHeight (irr::s32 kerning) {}
|
||||
|
||||
//! Not yet supported
|
||||
virtual irr::s32 getKerningWidth(const wchar_t* thisLetter=0, const wchar_t* previousLetter=0) const { return 0; }
|
||||
|
||||
//! Not yet supported
|
||||
virtual irr::s32 getKerningHeight() const { return 0; }
|
||||
|
||||
//! Not yet supported
|
||||
virtual void setInvisibleCharacters( const wchar_t *s ) {}
|
||||
|
||||
|
||||
bool AntiAlias;
|
||||
bool Transparency;
|
||||
|
||||
protected:
|
||||
void clearGlyphs();
|
||||
|
||||
private:
|
||||
irr::u32 getWidthFromCharacter(wchar_t c) const;
|
||||
irr::u32 getGlyphByChar(wchar_t c) const;
|
||||
irr::video::IVideoDriver* Driver;
|
||||
irr::core::array< CGUITTGlyph* > Glyphs;
|
||||
CGUITTFace * TrueTypeFace;
|
||||
mutable irr::core::dimension2d<irr::u32> LargestGlyph;
|
||||
};
|
||||
|
||||
#endif // #if COMPILE_WITH_FREETYPE
|
||||
|
||||
#endif // _GUI_FREETYPE_FONT_H
|
||||
|
||||
@@ -47,12 +47,12 @@
|
||||
#include <limits>
|
||||
#include <iomanip>
|
||||
#include "rc_defines.h"
|
||||
#include "rc_stdlib.h"
|
||||
#include "rc_media.h"
|
||||
#include "rc_stdlib.h"
|
||||
#include "rc_gfx.h"
|
||||
#include "rc_matrix.h"
|
||||
#include "rc_geometry.h"
|
||||
#include "rc_geometry.h"
|
||||
#include <irrtheora.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#define LESS_FLAG 0
|
||||
#define LESS_EQUAL_FLAG 1
|
||||
@@ -76,7 +76,7 @@ bool CMP_FLAG_GREATER = false;
|
||||
bool CMP_FLAG_GREATER_EQUAL = false;
|
||||
bool CMP_FLAG_NOT_EQUAL = false;
|
||||
|
||||
string rcbasic_runtime_path = "";
|
||||
std::string rcbasic_runtime_path = "";
|
||||
|
||||
struct n_value
|
||||
{
|
||||
@@ -86,7 +86,7 @@ struct n_value
|
||||
|
||||
struct s_value
|
||||
{
|
||||
vector<string> value;
|
||||
vector<std::string> value;
|
||||
void * ref_parent; // This will be set by the obj_get instructions (ie. obj_get and obj_usr_get)
|
||||
};
|
||||
|
||||
@@ -103,7 +103,7 @@ struct rc_vm_n
|
||||
|
||||
struct rc_vm_s
|
||||
{
|
||||
string value;
|
||||
std::string value;
|
||||
s_value * r;
|
||||
uint64_t r_index;
|
||||
|
||||
@@ -316,7 +316,7 @@ struct rcbasic_debug_access_status
|
||||
int dimensions;
|
||||
int dim[3];
|
||||
double num_val;
|
||||
string str_val;
|
||||
std::string str_val;
|
||||
int reg;
|
||||
bool is_error = false;
|
||||
};
|
||||
@@ -324,14 +324,14 @@ struct rcbasic_debug_access_status
|
||||
struct rcbasic_debug_vars
|
||||
{
|
||||
int type;
|
||||
string scope;
|
||||
string name;
|
||||
std::string scope;
|
||||
std::string name;
|
||||
int index;
|
||||
vector<rcbasic_debug_access_status> usage_data;
|
||||
};
|
||||
|
||||
vector<rcbasic_debug_vars> dbg_vars;
|
||||
vector<string> dbg_files;
|
||||
vector<std::string> dbg_files;
|
||||
|
||||
uint64_t current_src_line = 1;
|
||||
uint64_t current_src_file = 0;
|
||||
@@ -343,16 +343,16 @@ uint64_t current_src_file = 0;
|
||||
#define DBG_REDIM_LEQ_ZERO "Array Size must be greater than Zero"
|
||||
|
||||
bool dbg_error_found = false;
|
||||
string dbg_error_message = "";
|
||||
std::string dbg_error_message = "";
|
||||
|
||||
|
||||
void loadDebugData(string sym_file, string inc_file)
|
||||
void loadDebugData(std::string sym_file, std::string inc_file)
|
||||
{
|
||||
fstream f(sym_file, fstream::in);
|
||||
|
||||
string f_line;
|
||||
std::string f_line;
|
||||
|
||||
string type_str = "";
|
||||
std::string type_str = "";
|
||||
rcbasic_debug_vars tmp;
|
||||
|
||||
while(!f.eof())
|
||||
@@ -421,16 +421,16 @@ void loadDebugData(string sym_file, string inc_file)
|
||||
while(!f.eof())
|
||||
{
|
||||
getline(f, f_line);
|
||||
if(f_line.find_first_not_of(" ")!=string::npos)
|
||||
if(f_line.find_first_not_of(" ")!=std::string::npos)
|
||||
dbg_files.push_back(f_line);
|
||||
}
|
||||
|
||||
f.close();
|
||||
}
|
||||
|
||||
string dbg_format_string(string dbg_str_val)
|
||||
std::string dbg_format_string(std::string dbg_str_val)
|
||||
{
|
||||
string rtn = dbg_str_val;
|
||||
std::string rtn = dbg_str_val;
|
||||
rtn = rc_intern_replace(rtn, "\n", "\\n");
|
||||
rtn = rc_intern_replace(rtn, "\r", "\\r");
|
||||
rtn = rc_intern_replace(rtn, "\t", "\\t");
|
||||
@@ -526,7 +526,7 @@ uint64_t rcbasic_readInt()
|
||||
}
|
||||
|
||||
|
||||
bool rcbasic_load(string filename)
|
||||
bool rcbasic_load(std::string filename)
|
||||
{
|
||||
char rc[5];
|
||||
|
||||
@@ -544,7 +544,7 @@ bool rcbasic_load(string filename)
|
||||
|
||||
if(! (rc[0]=='R' && rc[1] =='C' && rc[2]=='4') )
|
||||
{
|
||||
string rcs = rc;
|
||||
std::string rcs = rc;
|
||||
cout << "This program was not built for this version of the runtime: " << rcs << endl;
|
||||
return false;
|
||||
}
|
||||
@@ -654,42 +654,6 @@ bool rcbasic_load(string filename)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool rc_checkEvent()
|
||||
{
|
||||
for(int i = 0; i < MAX_WINDOWS; i++)
|
||||
if(rc_win[i]!=NULL)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void rc_events()
|
||||
{
|
||||
//rc_textinput_flag = false;
|
||||
cycleVideo();
|
||||
if(rc_checkEvent())
|
||||
{
|
||||
rc_fingers_pressed.clear();
|
||||
rc_inkey = 0;
|
||||
rc_mouseX = -1;
|
||||
rc_mouseY = -1;
|
||||
rc_global_mouseX = -1;
|
||||
rc_global_mouseY = -1;
|
||||
rc_mwheelx = 0;
|
||||
rc_mwheely = 0;
|
||||
for(int i = 0; i < MAX_WINDOWS; i++)
|
||||
rc_win_event[i] = 0;
|
||||
while(rc_getEvents()){}
|
||||
keyState = SDL_GetKeyboardState(NULL);
|
||||
SDL_GetMouseState(&rc_mouseX, &rc_mouseY);
|
||||
SDL_GetGlobalMouseState(&rc_global_mouseX, &rc_global_mouseY);
|
||||
//rc_getEvents();
|
||||
#ifndef RC_WINDOWS
|
||||
SDL_PumpEvents();
|
||||
#endif // RC_WINDOWS
|
||||
//SDL_FlushEvents(SDL_FIRSTEVENT, SDL_LASTEVENT);//
|
||||
}
|
||||
}
|
||||
|
||||
uint64_t readInt()
|
||||
{
|
||||
for(int i = 0; i < sizeof(uint64_t); i++)
|
||||
@@ -2175,9 +2139,9 @@ void rc_print_num(double n)
|
||||
{
|
||||
stringstream s;
|
||||
s << fixed << n;
|
||||
string s_out = s.str();
|
||||
std::string s_out = s.str();
|
||||
int s_decimal = s_out.find_first_of(".");
|
||||
if(s_decimal != string::npos)
|
||||
if(s_decimal != std::string::npos)
|
||||
{
|
||||
int trail_end = s_out.length();
|
||||
for(int i = s_decimal; i < s_out.length(); i++)
|
||||
@@ -2210,7 +2174,7 @@ void rc_push_num(double n_val)
|
||||
//current_n_stack_count++;
|
||||
}
|
||||
|
||||
void rc_push_str(string s_val)
|
||||
void rc_push_str(std::string s_val)
|
||||
{
|
||||
rc_vm_s s;
|
||||
s.value = s_val;
|
||||
@@ -2521,7 +2485,7 @@ void rc_number_array_fill(rc_numId* n_var, double n)
|
||||
}
|
||||
|
||||
|
||||
void rc_string_array_fill(rc_strId* s_var, string s)
|
||||
void rc_string_array_fill(rc_strId* s_var, std::string s)
|
||||
{
|
||||
uint64_t src_dim, src_dim_size[3];
|
||||
rc_strId* src = (rc_strId*)s_var->sid_value.ref_parent;
|
||||
@@ -4401,13 +4365,13 @@ int main(int argc, char * argv[])
|
||||
#ifdef RC_GETCWD
|
||||
char buf[2048];
|
||||
getcwd(buf, 2048);
|
||||
rc_dir_path = (string)buf;
|
||||
rc_dir_path = (std::string)buf;
|
||||
#else
|
||||
rc_dir_path = get_current_dir_name();
|
||||
#endif
|
||||
#endif // RC_WINDOWS
|
||||
|
||||
string rc_filename = "main.cbc";
|
||||
std::string rc_filename = "main.cbc";
|
||||
|
||||
if(argc > 1)
|
||||
rc_filename = argv[1];
|
||||
@@ -4441,7 +4405,7 @@ int main(int argc, char * argv[])
|
||||
if(argc >1)
|
||||
{
|
||||
rc_cmd_count = argc - 1;
|
||||
rc_cmd_args = new string[rc_cmd_count];
|
||||
rc_cmd_args = new std::string[rc_cmd_count];
|
||||
for(int i = 1; i < argc; i++)
|
||||
rc_cmd_args[i-1] = argv[i];
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
6
rcbasic_runtime/rc_font.h
Normal file
6
rcbasic_runtime/rc_font.h
Normal file
@@ -0,0 +1,6 @@
|
||||
#ifndef RC_FONT_H_INCLUDED
|
||||
#define RC_FONT_H_INCLUDED
|
||||
|
||||
|
||||
|
||||
#endif // RC_FONT_H_INCLUDED
|
||||
2498
rcbasic_runtime/rc_func130_cases.h
Normal file
2498
rcbasic_runtime/rc_func130_cases.h
Normal file
File diff suppressed because it is too large
Load Diff
3739
rcbasic_runtime/rc_gfx.h
Normal file
3739
rcbasic_runtime/rc_gfx.h
Normal file
File diff suppressed because it is too large
Load Diff
6728
rcbasic_runtime/rc_gfx3D.h
Normal file
6728
rcbasic_runtime/rc_gfx3D.h
Normal file
File diff suppressed because it is too large
Load Diff
595
rcbasic_runtime/rc_gfx_core.h
Normal file
595
rcbasic_runtime/rc_gfx_core.h
Normal file
@@ -0,0 +1,595 @@
|
||||
#ifndef RC_GFX_CORE_H_INCLUDED
|
||||
#define RC_GFX_CORE_H_INCLUDED
|
||||
|
||||
#include <SDL2/SDL.h>
|
||||
#include <irrlicht.h>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
#include <cmath>
|
||||
#include <set>
|
||||
#include "gui_freetype_font.h"
|
||||
#include "rc_utf8.h"
|
||||
#include "camera.h"
|
||||
#include <box2d/box2d.h>
|
||||
#include "rc_sprite2D.h"
|
||||
#include <bullet/btBulletDynamicsCommon.h>
|
||||
#include <BulletSoftBody/btSoftRigidDynamicsWorld.h>
|
||||
#include <irrBullet.h>
|
||||
|
||||
using namespace irr;
|
||||
|
||||
using namespace core;
|
||||
using namespace video;
|
||||
using namespace scene;
|
||||
|
||||
|
||||
#define MAX_JOYSTICKS 8
|
||||
|
||||
#define MAX_FINGERS 10
|
||||
|
||||
#define MAX_ACCELS 20
|
||||
#define MAX_GYROS 20
|
||||
|
||||
SDL_Joystick * rc_joystick[MAX_JOYSTICKS];
|
||||
int rc_joy_axis[MAX_JOYSTICKS][100];
|
||||
int rc_numJoysticks = 0;
|
||||
int rc_joybutton[MAX_JOYSTICKS][100];
|
||||
SDL_JoystickID rc_joyID[MAX_JOYSTICKS];
|
||||
|
||||
SDL_Joystick * tmp_joy;
|
||||
SDL_JoystickID tmp_joy_id;
|
||||
int tmp_joy_flag = 0;
|
||||
|
||||
SDL_Haptic * rc_haptic[MAX_JOYSTICKS]; //1 for each joystick
|
||||
|
||||
double rc_pressure = 0;
|
||||
int rc_touchX = 0;
|
||||
int rc_touchY = 0;
|
||||
int rc_motionX = 0;
|
||||
int rc_motionY = 0;
|
||||
int rc_touch = 0;
|
||||
int rc_mt_status = 0;
|
||||
int rc_mt_x = 0;
|
||||
int rc_mt_y = 0;
|
||||
int rc_mt_numFingers = 0;
|
||||
double rc_mt_theta = 0;
|
||||
double rc_mt_dist = 0;
|
||||
SDL_TouchID rc_touchDevice;
|
||||
SDL_Finger rc_finger[MAX_FINGERS];
|
||||
set<int> rc_fingers_pressed;
|
||||
|
||||
SDL_Sensor * rc_accel[MAX_ACCELS];
|
||||
int num_accels = 0;
|
||||
|
||||
SDL_Sensor * rc_gyro[MAX_GYROS];
|
||||
int num_gyros = 0;
|
||||
|
||||
|
||||
struct SDLKeyMap
|
||||
{
|
||||
SDLKeyMap() {}
|
||||
SDLKeyMap(s32 x11, s32 win32)
|
||||
: SDLKey(x11), Win32Key(win32)
|
||||
{
|
||||
}
|
||||
|
||||
s32 SDLKey;
|
||||
s32 Win32Key;
|
||||
|
||||
bool operator<(const SDLKeyMap& o) const
|
||||
{
|
||||
return SDLKey<o.SDLKey;
|
||||
}
|
||||
};
|
||||
|
||||
core::array<SDLKeyMap> KeyMap;
|
||||
|
||||
void createKeyMap()
|
||||
{
|
||||
// I don't know if this is the best method to create
|
||||
// the lookuptable, but I'll leave it like that until
|
||||
// I find a better version.
|
||||
|
||||
KeyMap.reallocate(105);
|
||||
|
||||
// buttons missing
|
||||
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_BACKSPACE, irr::EKEY_CODE::KEY_BACK));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_TAB, irr::EKEY_CODE::KEY_TAB));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_CLEAR, irr::EKEY_CODE::KEY_CLEAR));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_RETURN, irr::EKEY_CODE::KEY_RETURN));
|
||||
|
||||
// combined modifiers missing
|
||||
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_PAUSE, irr::EKEY_CODE::KEY_PAUSE));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_CAPSLOCK, irr::EKEY_CODE::KEY_CAPITAL));
|
||||
|
||||
// asian letter keys missing
|
||||
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_ESCAPE, irr::EKEY_CODE::KEY_ESCAPE));
|
||||
|
||||
// asian letter keys missing
|
||||
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_SPACE, irr::EKEY_CODE::KEY_SPACE));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_PAGEUP, irr::EKEY_CODE::KEY_PRIOR));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_PAGEDOWN, irr::EKEY_CODE::KEY_NEXT));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_END, irr::EKEY_CODE::KEY_END));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_HOME, irr::EKEY_CODE::KEY_HOME));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_LEFT, irr::EKEY_CODE::KEY_LEFT));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_UP, irr::EKEY_CODE::KEY_UP));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_RIGHT, irr::EKEY_CODE::KEY_RIGHT));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_DOWN, irr::EKEY_CODE::KEY_DOWN));
|
||||
|
||||
// select missing
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_PRINTSCREEN, irr::EKEY_CODE::KEY_PRINT));
|
||||
// execute missing
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_PRINTSCREEN, irr::EKEY_CODE::KEY_SNAPSHOT));
|
||||
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_INSERT, irr::EKEY_CODE::KEY_INSERT));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_DELETE, irr::EKEY_CODE::KEY_DELETE));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_HELP, irr::EKEY_CODE::KEY_HELP));
|
||||
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_0, irr::EKEY_CODE::KEY_KEY_0));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_1, irr::EKEY_CODE::KEY_KEY_1));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_2, irr::EKEY_CODE::KEY_KEY_2));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_3, irr::EKEY_CODE::KEY_KEY_3));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_4, irr::EKEY_CODE::KEY_KEY_4));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_5, irr::EKEY_CODE::KEY_KEY_5));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_6, irr::EKEY_CODE::KEY_KEY_6));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_7, irr::EKEY_CODE::KEY_KEY_7));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_8, irr::EKEY_CODE::KEY_KEY_8));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_9, irr::EKEY_CODE::KEY_KEY_9));
|
||||
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_a, irr::EKEY_CODE::KEY_KEY_A));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_b, irr::EKEY_CODE::KEY_KEY_B));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_c, irr::EKEY_CODE::KEY_KEY_C));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_d, irr::EKEY_CODE::KEY_KEY_D));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_e, irr::EKEY_CODE::KEY_KEY_E));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_f, irr::EKEY_CODE::KEY_KEY_F));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_g, irr::EKEY_CODE::KEY_KEY_G));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_h, irr::EKEY_CODE::KEY_KEY_H));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_i, irr::EKEY_CODE::KEY_KEY_I));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_j, irr::EKEY_CODE::KEY_KEY_J));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_k, irr::EKEY_CODE::KEY_KEY_K));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_l, irr::EKEY_CODE::KEY_KEY_L));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_m, irr::EKEY_CODE::KEY_KEY_M));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_n, irr::EKEY_CODE::KEY_KEY_N));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_o, irr::EKEY_CODE::KEY_KEY_O));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_p, irr::EKEY_CODE::KEY_KEY_P));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_q, irr::EKEY_CODE::KEY_KEY_Q));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_r, irr::EKEY_CODE::KEY_KEY_R));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_s, irr::EKEY_CODE::KEY_KEY_S));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_t, irr::EKEY_CODE::KEY_KEY_T));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_u, irr::EKEY_CODE::KEY_KEY_U));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_v, irr::EKEY_CODE::KEY_KEY_V));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_w, irr::EKEY_CODE::KEY_KEY_W));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_x, irr::EKEY_CODE::KEY_KEY_X));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_y, irr::EKEY_CODE::KEY_KEY_Y));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_z, irr::EKEY_CODE::KEY_KEY_Z));
|
||||
|
||||
// TODO:
|
||||
//KeyMap.push_back(SDLKeyMap(SDLK_LSUPER, KEY_LWIN));
|
||||
// TODO:
|
||||
//KeyMap.push_back(SDLKeyMap(SDLK_RSUPER, KEY_RWIN));
|
||||
// apps missing
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_POWER, irr::EKEY_CODE::KEY_SLEEP)); //??
|
||||
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_KP_0, irr::EKEY_CODE::KEY_NUMPAD0));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_KP_1, irr::EKEY_CODE::KEY_NUMPAD1));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_KP_2, irr::EKEY_CODE::KEY_NUMPAD2));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_KP_3, irr::EKEY_CODE::KEY_NUMPAD3));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_KP_4, irr::EKEY_CODE::KEY_NUMPAD4));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_KP_5, irr::EKEY_CODE::KEY_NUMPAD5));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_KP_6, irr::EKEY_CODE::KEY_NUMPAD6));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_KP_7, irr::EKEY_CODE::KEY_NUMPAD7));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_KP_8, irr::EKEY_CODE::KEY_NUMPAD8));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_KP_9, irr::EKEY_CODE::KEY_NUMPAD9));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_KP_MULTIPLY, irr::EKEY_CODE::KEY_MULTIPLY));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_KP_PLUS, irr::EKEY_CODE::KEY_ADD));
|
||||
// KeyMap.push_back(SDLKeyMap(SDLK_KP_, KEY_SEPARATOR));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_KP_MINUS, irr::EKEY_CODE::KEY_SUBTRACT));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_KP_PERIOD, irr::EKEY_CODE::KEY_DECIMAL));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_KP_DIVIDE, irr::EKEY_CODE::KEY_DIVIDE));
|
||||
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_F1, irr::EKEY_CODE::KEY_F1));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_F2, irr::EKEY_CODE::KEY_F2));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_F3, irr::EKEY_CODE::KEY_F3));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_F4, irr::EKEY_CODE::KEY_F4));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_F5, irr::EKEY_CODE::KEY_F5));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_F6, irr::EKEY_CODE::KEY_F6));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_F7, irr::EKEY_CODE::KEY_F7));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_F8, irr::EKEY_CODE::KEY_F8));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_F9, irr::EKEY_CODE::KEY_F9));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_F10, irr::EKEY_CODE::KEY_F10));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_F11, irr::EKEY_CODE::KEY_F11));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_F12, irr::EKEY_CODE::KEY_F12));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_F13, irr::EKEY_CODE::KEY_F13));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_F14, irr::EKEY_CODE::KEY_F14));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_F15, irr::EKEY_CODE::KEY_F15));
|
||||
// no higher F-keys
|
||||
|
||||
// TODO:
|
||||
//KeyMap.push_back(SDLKeyMap(SDLK_NUMLOCK, KEY_NUMLOCK));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_SCROLLLOCK, irr::EKEY_CODE::KEY_SCROLL));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_LSHIFT, irr::EKEY_CODE::KEY_LSHIFT));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_RSHIFT, irr::EKEY_CODE::KEY_RSHIFT));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_LCTRL, irr::EKEY_CODE::KEY_LCONTROL));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_RCTRL, irr::EKEY_CODE::KEY_RCONTROL));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_LALT, irr::EKEY_CODE::KEY_LMENU));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_RALT, irr::EKEY_CODE::KEY_RMENU));
|
||||
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_PLUS, irr::EKEY_CODE::KEY_PLUS));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_COMMA, irr::EKEY_CODE::KEY_COMMA));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_MINUS, irr::EKEY_CODE::KEY_MINUS));
|
||||
KeyMap.push_back(SDLKeyMap(SDLK_PERIOD, irr::EKEY_CODE::KEY_PERIOD));
|
||||
|
||||
// some special keys missing
|
||||
|
||||
KeyMap.sort();
|
||||
}
|
||||
|
||||
IrrlichtDevice* device;
|
||||
irr::video::IVideoDriver * VideoDriver;
|
||||
irr::scene::ISceneManager *SceneManager;
|
||||
SDL_Window* rc_window;
|
||||
irr::core::dimension2d<u32> rc_window_size;
|
||||
|
||||
struct rc_scene_properties_obj
|
||||
{
|
||||
irr::scene::ISceneNode* sky = NULL;
|
||||
};
|
||||
|
||||
rc_scene_properties_obj rc_scene_properties;
|
||||
|
||||
#define RC_CONSTRAINT_TYPE_POINT 1
|
||||
#define RC_CONSTRAINT_TYPE_HINGE 2
|
||||
#define RC_CONSTRAINT_TYPE_SLIDER 3
|
||||
#define RC_CONSTRAINT_TYPE_CONE 4
|
||||
|
||||
struct rc_constraint_obj
|
||||
{
|
||||
btTypedConstraint* constraint;
|
||||
|
||||
int type;
|
||||
};
|
||||
|
||||
struct rc_physicsWorld3D_obj
|
||||
{
|
||||
irrBulletWorld* world;
|
||||
|
||||
irr::f32 DeltaTime;
|
||||
irr::u32 maxSubSteps;
|
||||
irr::f32 fixedTimeStep;
|
||||
|
||||
irr::u32 TimeStamp;
|
||||
|
||||
irr::core::array<rc_constraint_obj> constraints;
|
||||
};
|
||||
|
||||
rc_physicsWorld3D_obj rc_physics3D;
|
||||
|
||||
//Canvases
|
||||
struct rc_physicsWorld2D_obj
|
||||
{
|
||||
b2World* world;
|
||||
float timeStep = 1/20.0; //the length of time passed to simulate (seconds)
|
||||
int velocityIterations = 8; //how strongly to correct velocity
|
||||
int positionIterations = 3; //how strongly to correct position
|
||||
};
|
||||
|
||||
struct rc_canvas_obj
|
||||
{
|
||||
irr::video::ITexture* texture;
|
||||
|
||||
irr::video::ITexture* sprite_layer;
|
||||
|
||||
irr::core::dimension2d<u32> dimension;
|
||||
|
||||
struct rc_canvas_viewport
|
||||
{
|
||||
irr::core::vector2d<s32> position;
|
||||
irr::core::dimension2d<u32> dimension;
|
||||
} viewport;
|
||||
|
||||
|
||||
bool show3D = false;
|
||||
Camera camera;
|
||||
|
||||
irr::core::vector2d<s32> offset;
|
||||
|
||||
int mode;
|
||||
|
||||
bool visible = true;
|
||||
int z = 0;
|
||||
|
||||
irr::u32 color_mod;
|
||||
|
||||
rc_physicsWorld2D_obj physics2D;
|
||||
irr::core::array<rc_sprite2D_obj*> sprite;
|
||||
};
|
||||
|
||||
irr::core::array<rc_canvas_obj> rc_canvas;
|
||||
irr::core::array<u32> rc_canvas_zOrder;
|
||||
int rc_active_canvas = -1;
|
||||
|
||||
irr::video::SColor rc_active_color(0,0,0,0);
|
||||
irr::video::SColor rc_clear_color(0,0,0,0);
|
||||
|
||||
bool rc_init_events = false;
|
||||
bool rc_init_timer = false;
|
||||
bool rc_init_video = false;
|
||||
bool rc_init_joystick = false;
|
||||
bool rc_init_haptic = false;
|
||||
bool rc_init_sensor = false;
|
||||
bool rc_init_noparachute = false;
|
||||
bool rc_init_audio = false;
|
||||
|
||||
|
||||
irr::s32 MouseX, MouseY, MouseXRel, MouseYRel;
|
||||
irr::u32 MouseButtonStates;
|
||||
|
||||
|
||||
int rc_win_event = -1;
|
||||
#define RC_WIN_EVENT_CLOSE 1
|
||||
#define RC_WIN_EVENT_MINIMIZE 2
|
||||
#define RC_WIN_EVENT_MAXIMIZE 3
|
||||
#define RC_WIN_EVENT_RESIZE 4
|
||||
|
||||
bool rc_win_exitOnClose = true;
|
||||
|
||||
std::string rc_textinput_string = "";
|
||||
std::string rc_textinput_char = "";
|
||||
int rc_textinput_timer = 0;
|
||||
int rc_textinput_delay = 100;
|
||||
bool rc_textinput_flag = true;
|
||||
bool rc_textinput_isActive = false;
|
||||
int rc_textinput_waitHold = 800;
|
||||
bool rc_textinput_hold = false;
|
||||
bool rc_toggleBackspace = true;
|
||||
|
||||
|
||||
static Uint32 baseticks = 0;
|
||||
|
||||
int rc_inkey_val = 0;
|
||||
|
||||
const Uint8 * keyState = NULL;
|
||||
|
||||
|
||||
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
|
||||
struct rc_font_obj
|
||||
{
|
||||
CGUITTFace* face;
|
||||
CGUIFreetypeFont* font;
|
||||
int font_size;
|
||||
};
|
||||
|
||||
irr::core::array<rc_font_obj*> rc_font;
|
||||
|
||||
int rc_active_font = -1;
|
||||
|
||||
|
||||
bool mobile_active_window_flag = true;
|
||||
|
||||
|
||||
|
||||
//------------ 3D Graphics ----------------//
|
||||
#define RC_MESH_TYPE_NONE 0
|
||||
#define RC_MESH_TYPE_ANIMATED 1
|
||||
|
||||
|
||||
struct rc_mesh_obj
|
||||
{
|
||||
int mesh_type = 0;
|
||||
irr::scene::IAnimatedMesh* mesh;
|
||||
};
|
||||
irr::core::array<rc_mesh_obj> rc_mesh;
|
||||
|
||||
#define RC_NODE_TYPE_NONE 0
|
||||
#define RC_NODE_TYPE_MESH 1
|
||||
#define RC_NODE_TYPE_OTMESH 2
|
||||
#define RC_NODE_TYPE_LIGHT 3
|
||||
#define RC_NODE_TYPE_TERRAIN 4
|
||||
#define RC_NODE_TYPE_WATER 5
|
||||
#define RC_NODE_TYPE_BILLBOARD 6
|
||||
#define RC_NODE_TYPE_PARTICLE 7
|
||||
|
||||
|
||||
#define RC_NODE_SHAPE_TYPE_NONE 0
|
||||
#define RC_NODE_SHAPE_TYPE_BOX 1
|
||||
#define RC_NODE_SHAPE_TYPE_SPHERE 2
|
||||
#define RC_NODE_SHAPE_TYPE_CYLINDER 3
|
||||
#define RC_NODE_SHAPE_TYPE_CAPSULE 4
|
||||
#define RC_NODE_SHAPE_TYPE_CONE 5
|
||||
#define RC_NODE_SHAPE_TYPE_CONVEXHULL 6
|
||||
#define RC_NODE_SHAPE_TYPE_TRIMESH 7
|
||||
#define RC_NODE_SHAPE_TYPE_HEIGHTFIELD 8
|
||||
|
||||
struct rc_node_physics_collision
|
||||
{
|
||||
int actorA;
|
||||
int actorB;
|
||||
irr::core::array<irr::core::vector3df> pointA;
|
||||
irr::core::array<irr::core::vector3df> pointB;
|
||||
irr::core::array<irr::core::vector3df> normalB;
|
||||
};
|
||||
|
||||
irr::core::array<rc_node_physics_collision> rc_collisions;
|
||||
|
||||
struct rc_node_physics
|
||||
{
|
||||
IRigidBody* rigid_body;
|
||||
|
||||
int shape_type;
|
||||
bool isSolid;
|
||||
double mass;
|
||||
|
||||
irr::core::vector3df gravity; //only used when changing from Solid to Non-Solid and vice versa
|
||||
|
||||
irr::core::array<irr::u32> collisions;
|
||||
};
|
||||
|
||||
#define RC_PARTICLE_TYPE_POINT 1
|
||||
#define RC_PARTICLE_TYPE_BOX 2
|
||||
#define RC_PARTICLE_TYPE_SPHERE 3
|
||||
#define RC_PARTICLE_TYPE_CYLINDER 4
|
||||
#define RC_PARTICLE_TYPE_MESH 5
|
||||
#define RC_PARTICLE_TYPE_RING 6
|
||||
|
||||
struct rc_particle_properties_obj
|
||||
{
|
||||
int particle_type = 0;
|
||||
bool everyMeshVertex;
|
||||
irr::s32 mbNumber = 0;
|
||||
irr::f32 normalDirectionModifier;
|
||||
bool useNormalDirection;
|
||||
irr::s32 mesh_id;
|
||||
irr::core::vector3df direction;
|
||||
irr::u32 minParticlesPerSecond;
|
||||
irr::u32 maxParticlesPerSecond;
|
||||
irr::video::SColor minStartColor;
|
||||
irr::video::SColor maxStartColor;
|
||||
irr::u32 lifeTimeMin;
|
||||
irr::u32 lifeTimeMax;
|
||||
irr::s32 maxAngleDegrees;
|
||||
irr::core::dimension2df minStartSize;
|
||||
irr::core::dimension2df maxStartSize;
|
||||
irr::core::vector3df center;
|
||||
irr::f32 radius;
|
||||
irr::f32 ringThickness;
|
||||
irr::core::aabbox3df box;
|
||||
irr::core::vector3df normal;
|
||||
irr::f32 length;
|
||||
bool outlineOnly;
|
||||
};
|
||||
|
||||
struct rc_scene_node
|
||||
{
|
||||
int node_type = 0;
|
||||
|
||||
irr::scene::ISceneNode* mesh_node;
|
||||
irr::scene::IShadowVolumeSceneNode* shadow;
|
||||
rc_node_physics physics;
|
||||
|
||||
bool transition;
|
||||
double transition_time;
|
||||
double transition_start_time;
|
||||
|
||||
rc_particle_properties_obj particle_properties;
|
||||
|
||||
int material_ref_index = -1;
|
||||
};
|
||||
|
||||
irr::core::array<rc_scene_node> rc_actor;
|
||||
|
||||
irr::core::array<int> rc_transition_actor;
|
||||
|
||||
|
||||
void myTickCallback2(btSoftRigidDynamicsWorld* dynamicsWorld, btScalar timeStep)
|
||||
{
|
||||
rc_collisions.clear();
|
||||
int numManifolds = dynamicsWorld->getDispatcher()->getNumManifolds();
|
||||
|
||||
int c_index = 0;
|
||||
|
||||
rc_node_physics_collision collision;
|
||||
|
||||
for(int i = 0; i < rc_actor.size(); i++)
|
||||
{
|
||||
rc_actor[i].physics.collisions.clear();
|
||||
}
|
||||
|
||||
|
||||
for (int i = 0; i < rc_physics3D.world->getNumManifolds(); i++)
|
||||
{
|
||||
ICollisionCallbackInformation* manifold = rc_physics3D.world->getCollisionCallback(i);
|
||||
|
||||
int numContacts = manifold->getPointer()->getNumContacts();
|
||||
|
||||
int actorA = manifold->getBody0()->getIdentification()->getId();
|
||||
int actorB = manifold->getBody1()->getIdentification()->getId();
|
||||
|
||||
collision.actorA = actorA;
|
||||
collision.actorB = actorB;
|
||||
|
||||
//std::cout << "Collision Details: " << actorA << ", " << actorB << ", " << numContacts << std::endl;
|
||||
|
||||
if(numContacts < 1)
|
||||
continue;
|
||||
|
||||
for (int j = 0; j < numContacts; j++)
|
||||
{
|
||||
SManifoldPoint pt = manifold->getContactPoint(j);
|
||||
collision.pointA.push_back(pt.getPositionWorldOnA());
|
||||
collision.pointB.push_back(pt.getPositionWorldOnB());
|
||||
collision.normalB.push_back(pt.getNormalWorldOnB());
|
||||
}
|
||||
|
||||
c_index = rc_collisions.size();
|
||||
rc_collisions.push_back(collision);
|
||||
rc_actor[actorA].physics.collisions.push_back(c_index);
|
||||
rc_actor[actorB].physics.collisions.push_back(c_index);
|
||||
}
|
||||
|
||||
for(int i = 0; i < rc_actor.size(); i++)
|
||||
{
|
||||
if(!rc_actor[i].physics.isSolid)
|
||||
{
|
||||
if(rc_actor[i].physics.collisions.size() > 0)
|
||||
{
|
||||
rc_physics3D.world->removeCollisionObject(rc_actor[i].physics.rigid_body, false);
|
||||
rc_physics3D.world->addRigidBody(rc_actor[i].physics.rigid_body);
|
||||
rc_actor[i].physics.rigid_body->setMassProps(1, irr::core::vector3df(0,0,0));
|
||||
rc_actor[i].physics.rigid_body->setGravity(irr::core::vector3df(0,0,0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#define RC_ACTOR_TEXTURE_TYPE_IMAGE 0
|
||||
#define RC_ACTOR_TEXTURE_TYPE_CANVAS 1
|
||||
|
||||
|
||||
// Function to calculate a point on a cubic Bezier curve
|
||||
vector3df bezierPoint(const vector3df& p0, const vector3df& p1, const vector3df& p2, const vector3df& p3, float t) {
|
||||
float u = 1.0f - t;
|
||||
float tt = t * t;
|
||||
float uu = u * u;
|
||||
float uuu = uu * u;
|
||||
float ttt = tt * t;
|
||||
|
||||
vector3df p = uuu * p0; // (1-t)^3 * p0
|
||||
p += 3 * uu * t * p1; // 3 * (1-t)^2 * t * p1
|
||||
p += 3 * u * tt * p2; // 3 * (1-t) * t^2 * p2
|
||||
p += ttt * p3; // t^3 * p3
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
// Function to draw a Bezier curve
|
||||
void drawBezierCurve(IVideoDriver* driver, const vector3df& p0, const vector3df& p1, const vector3df& p2, const vector3df& p3, SColor color, int segments) {
|
||||
std::vector<vector3df> points;
|
||||
|
||||
for (int i = 0; i <= segments; ++i) {
|
||||
float t = static_cast<float>(i) / segments;
|
||||
points.push_back(bezierPoint(p0, p1, p2, p3, t));
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < points.size() - 1; ++i) {
|
||||
driver->draw3DLine(points[i], points[i + 1], color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printIrrMatrix(irr::core::matrix4 m)
|
||||
{
|
||||
for(int i = 0; i < 4; i++)
|
||||
std::cout << "[ " << m[i*4] << ", " << m[i*4+1] << ", " << m[i*4+2] << ", " << m[i*4+3] << " ]" << std::endl;
|
||||
}
|
||||
|
||||
#endif // RC_GFX_CORE_H_INCLUDED
|
||||
@@ -11,7 +11,9 @@
|
||||
#endif
|
||||
#endif
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <ctime>
|
||||
|
||||
#include <irrlicht.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@@ -22,21 +24,47 @@ int64_t rand_int(int64_t vmin, int64_t vmax) {
|
||||
|
||||
|
||||
struct rc_matrix_type
|
||||
{
|
||||
{
|
||||
bool active = false;
|
||||
uint32_t r = 0;
|
||||
uint32_t c = 0;
|
||||
vector<double> data;
|
||||
};
|
||||
|
||||
rc_matrix_type rc_matrix[1048];
|
||||
std::vector<rc_matrix_type> rc_matrix(64);
|
||||
|
||||
#define RC_TMP_MATRIX 1024
|
||||
#define RC_TMP_MATRIX_2 1025
|
||||
|
||||
#define RC_PROCESS_TMP_MATRIX_OFFSET 1026
|
||||
|
||||
#define NEW_MATRIX -1
|
||||
|
||||
int DimMatrix(int m, uint32_t m_rows, uint32_t m_cols, bool preserve_flag=false)
|
||||
{
|
||||
if(m < 0)
|
||||
{
|
||||
for(int i = 0; i < rc_matrix.size(); i++)
|
||||
{
|
||||
if(!rc_matrix[i].active)
|
||||
{
|
||||
m = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(m < 0)
|
||||
{
|
||||
rc_matrix_type mat;
|
||||
mat.active = true;
|
||||
m = rc_matrix.size();
|
||||
rc_matrix.push_back(mat);
|
||||
}
|
||||
}
|
||||
|
||||
if(!preserve_flag)
|
||||
rc_matrix[m].data.clear();
|
||||
|
||||
void DimMatrix(int m, uint32_t m_rows, uint32_t m_cols, bool preserve_flag=false)
|
||||
{
|
||||
rc_matrix[m].data.resize(m_rows*m_cols);
|
||||
|
||||
if(rc_matrix[m].c != m_cols && preserve_flag)
|
||||
@@ -56,7 +84,18 @@ void DimMatrix(int m, uint32_t m_rows, uint32_t m_cols, bool preserve_flag=false
|
||||
}
|
||||
|
||||
rc_matrix[m].r = m_rows;
|
||||
rc_matrix[m].c = m_cols;
|
||||
rc_matrix[m].c = m_cols;
|
||||
rc_matrix[m].active = true;
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
void DeleteMatrix(int mA)
|
||||
{
|
||||
rc_matrix[mA].data.clear();
|
||||
rc_matrix[mA].c = 0;
|
||||
rc_matrix[mA].r = 0;
|
||||
rc_matrix[mA].active = false;
|
||||
}
|
||||
|
||||
//Adds Matrix A() to Matrix B(), answer is Matrix C()
|
||||
@@ -503,11 +542,11 @@ bool GetMatrixRows (uint32_t mA, uint32_t mB, uint32_t r, uint32_t num_rows)
|
||||
}
|
||||
|
||||
// Creates Identity Matrix A() of order N%
|
||||
void IdentityMatrix(uint32_t mA, uint32_t n)
|
||||
void setIdentityMatrix(uint32_t mA, uint32_t n)
|
||||
{
|
||||
DimMatrix(mA, n, n);
|
||||
for(int i = 0; i < n; i++)
|
||||
rc_matrix[mA].data[i*n+n] = 1;
|
||||
rc_matrix[mA].data[i*(n+1)] = 1;
|
||||
}
|
||||
|
||||
bool GaussianElimination(vector< vector<double> > &A, vector<double> &b, uint32_t mC) {
|
||||
@@ -630,7 +669,7 @@ void getCofactor(uint32_t A_dim, double* A, double* temp, int p, int q,
|
||||
}
|
||||
}
|
||||
|
||||
bool CofactorMatrix(uint32_t mA, int p, int q, int n)
|
||||
void CofactorMatrix(uint32_t mA, int p, int q, int n)
|
||||
{
|
||||
|
||||
uint32_t m_size = rc_matrix[mA].c;
|
||||
@@ -1184,6 +1223,136 @@ void JoinMatrixColumns(uint32_t mA, uint32_t mB, uint32_t mC)
|
||||
SetMatrixValue(mC, rc_matrix[mA].r + r, c, mv);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ClipMatrix(int mA, int r, int c, int num_rows, int num_cols, int mB)
|
||||
{
|
||||
int mA_rows = rc_matrix[mA].r;
|
||||
int mA_cols = rc_matrix[mA].c;
|
||||
|
||||
int mB_rows = num_rows;
|
||||
int mB_cols = num_cols;
|
||||
|
||||
if((r + num_rows) > mA_rows)
|
||||
mB_rows = mA_rows - r;
|
||||
|
||||
if(mB_rows < 0)
|
||||
{
|
||||
DimMatrix(mB, mA_rows, mA_cols, false);
|
||||
ClearMatrix(mB);
|
||||
return;
|
||||
}
|
||||
|
||||
if((c + num_cols) > mA_cols)
|
||||
mB_cols = mA_cols - c;
|
||||
|
||||
if(mB_cols < 0)
|
||||
{
|
||||
DimMatrix(mB, mA_rows, mA_cols, false);
|
||||
ClearMatrix(mB);
|
||||
return;
|
||||
}
|
||||
|
||||
DimMatrix(mB, mB_rows, mB_cols, false);
|
||||
|
||||
for(int row = r; row < (r+num_rows); row++)
|
||||
for(int col = c; col < (c+num_cols); col++)
|
||||
SetMatrixValue( mB, row-r, col-c, MatrixValue(mA, row, col));
|
||||
}
|
||||
|
||||
int rc_convertFromIrrMatrix(irr::core::matrix4 irr_mat, int mB = -1)
|
||||
{
|
||||
int mA = DimMatrix(NEW_MATRIX, 4, 4);
|
||||
|
||||
if(mB < 0)
|
||||
mB = DimMatrix(NEW_MATRIX, 4, 4);
|
||||
else
|
||||
DimMatrix(mB, 4, 4);
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
rc_matrix[mA].data[i*4] = irr_mat[i*4];
|
||||
rc_matrix[mA].data[i*4+1] = irr_mat[i*4+1];
|
||||
rc_matrix[mA].data[i*4+2] = irr_mat[i*4+2];
|
||||
rc_matrix[mA].data[i*4+3] = irr_mat[i*4+3];
|
||||
}
|
||||
|
||||
TransposeMatrix(mA, mB);
|
||||
DeleteMatrix(mA);
|
||||
return mB;
|
||||
}
|
||||
|
||||
irr::core::matrix4 rc_convertToIrrMatrix(int mA)
|
||||
{
|
||||
int mB = DimMatrix(NEW_MATRIX, 4, 4);
|
||||
TransposeMatrix(mA, mB);
|
||||
|
||||
irr::core::matrix4 irr_mat;
|
||||
|
||||
for(int i = 0; i < 4; i++)
|
||||
{
|
||||
irr_mat[i*4] = rc_matrix[mB].data[i*4];
|
||||
irr_mat[i*4+1] = rc_matrix[mB].data[i*4+1];
|
||||
irr_mat[i*4+2] = rc_matrix[mB].data[i*4+2];
|
||||
irr_mat[i*4+3] = rc_matrix[mB].data[i*4+3];
|
||||
}
|
||||
|
||||
DeleteMatrix(mB);
|
||||
return irr_mat;
|
||||
}
|
||||
|
||||
void printRCMatrix(int m)
|
||||
{
|
||||
for(int i = 0; i < 4; i++)
|
||||
std::cout << "[ " << rc_matrix[m].data[i*4] << ", " << rc_matrix[m].data[i*4+1] << ", " << rc_matrix[m].data[i*4+2] << ", " << rc_matrix[m].data[i*4+3] << " ]" << std::endl;
|
||||
}
|
||||
|
||||
|
||||
void rc_setMatrixTranslation(int mA, double x, double y, double z)
|
||||
{
|
||||
irr::core::matrix4 m = rc_convertToIrrMatrix(mA);
|
||||
m.setTranslation(irr::core::vector3df(x, y, z));
|
||||
rc_convertFromIrrMatrix(m, mA);
|
||||
}
|
||||
|
||||
void rc_setMatrixRotation(int mA, double x, double y, double z)
|
||||
{
|
||||
irr::core::matrix4 m = rc_convertToIrrMatrix(mA);
|
||||
m.setRotationDegrees(irr::core::vector3df(x, y, z));
|
||||
rc_convertFromIrrMatrix(m, mA);
|
||||
}
|
||||
|
||||
void rc_setMatrixScale(int mA, double x, double y, double z)
|
||||
{
|
||||
irr::core::matrix4 m = rc_convertToIrrMatrix(mA);
|
||||
m.setScale(irr::core::vector3df(x, y, z));
|
||||
rc_convertFromIrrMatrix(m, mA);
|
||||
}
|
||||
|
||||
void rc_getMatrixTranslation(int mA, double* x, double* y, double* z)
|
||||
{
|
||||
irr::core::matrix4 m = rc_convertToIrrMatrix(mA);
|
||||
*x = m.getTranslation().X;
|
||||
*y = m.getTranslation().Y;
|
||||
*z = m.getTranslation().Z;
|
||||
}
|
||||
|
||||
void rc_getMatrixRotation(int mA, double* x, double* y, double* z)
|
||||
{
|
||||
irr::core::matrix4 m = rc_convertToIrrMatrix(mA);
|
||||
*x = m.getRotationDegrees().X;
|
||||
*y = m.getRotationDegrees().Y;
|
||||
*z = m.getRotationDegrees().Z;
|
||||
}
|
||||
|
||||
void rc_getMatrixScale(int mA, double* x, double* y, double* z)
|
||||
{
|
||||
irr::core::matrix4 m = rc_convertToIrrMatrix(mA);
|
||||
*x = m.getScale().X;
|
||||
*y = m.getScale().Y;
|
||||
*z = m.getScale().Z;
|
||||
}
|
||||
|
||||
#endif // RC_MATRIX_H_INCLUDED
|
||||
|
||||
36
rcbasic_runtime/rc_sprite2D.h
Normal file
36
rcbasic_runtime/rc_sprite2D.h
Normal file
@@ -0,0 +1,36 @@
|
||||
#ifndef RC_SPRITE2D_H_INCLUDED
|
||||
#define RC_SPRITE2D_H_INCLUDED
|
||||
|
||||
#include <irrlicht.h>
|
||||
#include <box2d/box2d.h>
|
||||
|
||||
struct rc_sprite2D_physics_obj
|
||||
{
|
||||
b2Body* body;
|
||||
};
|
||||
|
||||
struct rc_sprite2D_obj
|
||||
{
|
||||
bool active = false;
|
||||
int image_id;
|
||||
irr::core::vector2d<irr::f64> position;
|
||||
irr::f64 rotation;
|
||||
irr::core::vector2d<irr::f64> scale;
|
||||
|
||||
bool visible = true;
|
||||
Uint8 alpha;
|
||||
|
||||
irr::video::SColor color_mod;
|
||||
|
||||
bool physics_enabled = false;
|
||||
rc_sprite2D_physics_obj physics;
|
||||
|
||||
int parent_canvas = -1;
|
||||
|
||||
double z;
|
||||
};
|
||||
|
||||
irr::core::array<rc_sprite2D_obj> rc_sprite;
|
||||
|
||||
|
||||
#endif // RC_SPRITE2D_H_INCLUDED
|
||||
@@ -71,20 +71,20 @@ using namespace std;
|
||||
|
||||
struct dirent *rc_entry;
|
||||
DIR *rc_dir;
|
||||
string rc_dir_path = "";
|
||||
std::string rc_dir_path = "";
|
||||
|
||||
#else
|
||||
|
||||
struct dirent *rc_entry;
|
||||
string rc_dir;
|
||||
string rc_dir_path = "";
|
||||
std::string rc_dir;
|
||||
std::string rc_dir_path = "";
|
||||
HANDLE hfind;
|
||||
|
||||
#endif // RC_LINUX
|
||||
|
||||
|
||||
int rc_cmd_count = 0;
|
||||
string * rc_cmd_args;
|
||||
std::string * rc_cmd_args;
|
||||
|
||||
|
||||
SDL_RWops * rc_fstream[RC_MAX_FILES];
|
||||
@@ -94,8 +94,20 @@ bool rc_eof[RC_MAX_FILES];
|
||||
int rc_user_active_n_stack = 0;
|
||||
int rc_user_active_s_stack = 0;
|
||||
|
||||
stack<double> rc_user_n_stack[MAX_USER_STACKS];
|
||||
stack<string> rc_user_s_stack[MAX_USER_STACKS];
|
||||
struct rc_num_stack_obj
|
||||
{
|
||||
bool active = false;
|
||||
stack<double> data;
|
||||
};
|
||||
|
||||
struct rc_str_stack_obj
|
||||
{
|
||||
bool active = false;
|
||||
stack<std::string> data;
|
||||
};
|
||||
|
||||
vector<rc_num_stack_obj> rc_user_n_stack;
|
||||
vector<rc_str_stack_obj> rc_user_s_stack;
|
||||
|
||||
#ifdef RC_WINDOWS
|
||||
#define MAX_INPUT_LENGTH 32767
|
||||
@@ -138,16 +150,16 @@ std::size_t utf8_length(std::string const &s)
|
||||
}
|
||||
|
||||
|
||||
void rc_fprint(string txt)
|
||||
void rc_fprint(std::string txt)
|
||||
{
|
||||
cout << txt;
|
||||
}
|
||||
|
||||
string rc_input(string prompt)
|
||||
std::string rc_input(std::string prompt)
|
||||
{
|
||||
#ifdef RC_WINDOWS
|
||||
|
||||
string line = "";
|
||||
std::string line = "";
|
||||
cout << prompt;
|
||||
|
||||
unsigned long read;
|
||||
@@ -167,11 +179,11 @@ string rc_input(string prompt)
|
||||
mb_str[s_size-1] = 0;
|
||||
}
|
||||
|
||||
return (string) mb_str;
|
||||
return (std::string) mb_str;
|
||||
|
||||
#else
|
||||
|
||||
string line = "";
|
||||
std::string line = "";
|
||||
cout << prompt;
|
||||
getline(cin, line);
|
||||
return line;
|
||||
@@ -185,12 +197,12 @@ std::u32string to_utf32(const std::string &s)
|
||||
return conv.from_bytes(s);
|
||||
}
|
||||
|
||||
inline int rc_intern_asc(string c)
|
||||
inline int rc_intern_asc(std::string c)
|
||||
{
|
||||
return (uint32_t)to_utf32(utf8_substr(c, 0, 1))[0];
|
||||
}
|
||||
|
||||
inline size_t rc_intern_bufferFromString(string s, double* buffer)
|
||||
inline size_t rc_intern_bufferFromString(std::string s, double* buffer)
|
||||
{
|
||||
for(int i = 0; i < s.length(); i++)
|
||||
{
|
||||
@@ -241,14 +253,14 @@ std::string cpToUTF8(uint32_t cp)
|
||||
return std::string(utf8, len);
|
||||
}
|
||||
|
||||
inline string rc_intern_chr(uint32_t n)
|
||||
inline std::string rc_intern_chr(uint32_t n)
|
||||
{
|
||||
string s = cpToUTF8(n);
|
||||
std::string s = cpToUTF8(n);
|
||||
//s += (char) n;
|
||||
return s;
|
||||
}
|
||||
|
||||
inline string rc_intern_insert(string src, string tgt, size_t pos)
|
||||
inline std::string rc_intern_insert(std::string src, std::string tgt, size_t pos)
|
||||
{
|
||||
if(pos < 0 || pos > utf8_length(src))
|
||||
return src;
|
||||
@@ -256,7 +268,7 @@ inline string rc_intern_insert(string src, string tgt, size_t pos)
|
||||
return utf8_substr(src, 0, pos) + tgt + utf8_substr(src, pos, utf8_length(src)-pos);
|
||||
}
|
||||
|
||||
inline double rc_intern_instr(string in_string, string in_substring)
|
||||
inline double rc_intern_instr(std::string in_string, std::string in_substring)
|
||||
{
|
||||
//cout << "Cant find " << rc_sid[INSTR_SUBSTR][0] << " in " << rc_sid[INSTR_STR][0] << endl;
|
||||
bool found = false;
|
||||
@@ -275,9 +287,9 @@ inline double rc_intern_instr(string in_string, string in_substring)
|
||||
return found ? (double)n : -1;
|
||||
}
|
||||
|
||||
inline string rc_intern_lcase(string u_string)
|
||||
inline std::string rc_intern_lcase(std::string u_string)
|
||||
{
|
||||
string u_string_out = "";
|
||||
std::string u_string_out = "";
|
||||
for(size_t i=0;i<u_string.length();i++)
|
||||
{
|
||||
u_string_out += tolower(u_string[i]);
|
||||
@@ -285,7 +297,7 @@ inline string rc_intern_lcase(string u_string)
|
||||
return u_string_out;
|
||||
}
|
||||
|
||||
inline string rc_intern_left(string l_string, size_t n)
|
||||
inline std::string rc_intern_left(std::string l_string, size_t n)
|
||||
{
|
||||
if(n >= utf8_length(l_string))
|
||||
return l_string;
|
||||
@@ -293,21 +305,21 @@ inline string rc_intern_left(string l_string, size_t n)
|
||||
return utf8_substr(l_string,0,n);
|
||||
}
|
||||
|
||||
inline size_t rc_intern_length(string l_string)
|
||||
inline size_t rc_intern_length(std::string l_string)
|
||||
{
|
||||
//cout << "DBG_LEN" << endl;
|
||||
return utf8_length(l_string);
|
||||
}
|
||||
|
||||
inline string rc_intern_ltrim(string l_string)
|
||||
inline std::string rc_intern_ltrim(std::string l_string)
|
||||
{
|
||||
size_t first_index = l_string.find_first_not_of(" ");
|
||||
if(first_index != string::npos)
|
||||
if(first_index != std::string::npos)
|
||||
return l_string.substr(first_index);
|
||||
return l_string;
|
||||
}
|
||||
|
||||
inline string rc_intern_mid(string m_string, size_t m_start, size_t n)
|
||||
inline std::string rc_intern_mid(std::string m_string, size_t m_start, size_t n)
|
||||
{
|
||||
//cout << "DBG_MID" << endl;
|
||||
if(m_start < 0 || n < 0)
|
||||
@@ -320,10 +332,10 @@ inline string rc_intern_mid(string m_string, size_t m_start, size_t n)
|
||||
return utf8_substr(m_string, m_start, n);
|
||||
}
|
||||
|
||||
inline string rc_intern_replaceSubstr(string src, string rpc, size_t pos)
|
||||
inline std::string rc_intern_replaceSubstr(std::string src, std::string rpc, size_t pos)
|
||||
{
|
||||
size_t rpc_i = 0;
|
||||
string n_str = utf8_substr(src, 0, pos);
|
||||
std::string n_str = utf8_substr(src, 0, pos);
|
||||
|
||||
if(pos < 0)
|
||||
return src;
|
||||
@@ -341,14 +353,14 @@ inline string rc_intern_replaceSubstr(string src, string rpc, size_t pos)
|
||||
return n_str;
|
||||
}
|
||||
|
||||
inline string rc_intern_replace(string src, string tgt, string rpc)
|
||||
inline std::string rc_intern_replace(std::string src, std::string tgt, std::string rpc)
|
||||
{
|
||||
if(tgt.length()==0)
|
||||
return src;
|
||||
size_t found_inc = rpc.length() > 0 ? rpc.length() : 1;
|
||||
size_t found = 0;
|
||||
found = src.find(tgt);
|
||||
while( found != string::npos && found < src.length())
|
||||
while( found != std::string::npos && found < src.length())
|
||||
{
|
||||
src = src.substr(0,found) + rpc + src.substr(found + tgt.length());
|
||||
found = src.find(tgt,found+found_inc);
|
||||
@@ -356,9 +368,9 @@ inline string rc_intern_replace(string src, string tgt, string rpc)
|
||||
return src;
|
||||
}
|
||||
|
||||
inline string rc_intern_reverse(string rpc_string)
|
||||
inline string rc_intern_reverse(std::string rpc_string)
|
||||
{
|
||||
string n_str = "";
|
||||
std::string n_str = "";
|
||||
if(rpc_string.length()==0)
|
||||
return "";
|
||||
|
||||
@@ -371,7 +383,7 @@ inline string rc_intern_reverse(string rpc_string)
|
||||
return n_str;
|
||||
}
|
||||
|
||||
inline string rc_intern_right(string src, size_t n)
|
||||
inline std::string rc_intern_right(std::string src, size_t n)
|
||||
{
|
||||
size_t src_length = utf8_length(src);
|
||||
if(n < 0)
|
||||
@@ -381,7 +393,7 @@ inline string rc_intern_right(string src, size_t n)
|
||||
return utf8_substr(src,src_length-n, src_length -(src_length-n));
|
||||
}
|
||||
|
||||
inline string rc_intern_rtrim(string src)
|
||||
inline std::string rc_intern_rtrim(std::string src)
|
||||
{
|
||||
if(src.length()==0)
|
||||
return "";
|
||||
@@ -398,12 +410,12 @@ inline string rc_intern_rtrim(string src)
|
||||
return utf8_substr(src,0,i+1);
|
||||
}
|
||||
|
||||
inline size_t rc_intern_size(string src)
|
||||
inline size_t rc_intern_size(std::string src)
|
||||
{
|
||||
return src.length();
|
||||
}
|
||||
|
||||
inline string rc_intern_stringFromBuffer(double* buffer, size_t buffer_size)
|
||||
inline std::string rc_intern_stringFromBuffer(double* buffer, size_t buffer_size)
|
||||
{
|
||||
if(buffer_size <= 0)
|
||||
return "";
|
||||
@@ -416,46 +428,46 @@ inline string rc_intern_stringFromBuffer(double* buffer, size_t buffer_size)
|
||||
}
|
||||
|
||||
c_buf[buffer_size] = '\0';
|
||||
return (string)c_buf;
|
||||
return (std::string)c_buf;
|
||||
}
|
||||
|
||||
inline string rc_intern_stringfill(string f_string, size_t n)
|
||||
inline string rc_intern_stringfill(std::string f_string, size_t n)
|
||||
{
|
||||
string f = "";
|
||||
std::string f = "";
|
||||
for(size_t i = 0; i < n; i++)
|
||||
f += f_string;
|
||||
return f;
|
||||
}
|
||||
|
||||
inline string rc_intern_str(double n)
|
||||
inline std::string rc_intern_str(double n)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << n;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
inline string rc_intern_str_f(double n)
|
||||
inline std::string rc_intern_str_f(double n)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << fixed << n;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
inline string rc_intern_str_s(double n)
|
||||
inline std::string rc_intern_str_s(double n)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << scientific << n;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
inline unsigned long rc_intern_tally(string t_string, string t_substring)
|
||||
inline unsigned long rc_intern_tally(std::string t_string, std::string t_substring)
|
||||
{
|
||||
size_t found = 0;
|
||||
string t_str = t_string;
|
||||
string t_substr = t_substring;
|
||||
std::string t_str = t_string;
|
||||
std::string t_substr = t_substring;
|
||||
found = t_str.find(t_substr);
|
||||
unsigned long tally_count = 0;
|
||||
while( found != string::npos)
|
||||
while( found != std::string::npos)
|
||||
{
|
||||
tally_count++;
|
||||
found = t_str.find(t_substr,found+1);
|
||||
@@ -463,14 +475,14 @@ inline unsigned long rc_intern_tally(string t_string, string t_substring)
|
||||
return tally_count;
|
||||
}
|
||||
|
||||
inline string rc_intern_trim(string t_string)
|
||||
inline std::string rc_intern_trim(std::string t_string)
|
||||
{
|
||||
return rc_intern_ltrim(rc_intern_rtrim(t_string));
|
||||
}
|
||||
|
||||
inline string rc_intern_ucase(string u_string)
|
||||
inline std::string rc_intern_ucase(std::string u_string)
|
||||
{
|
||||
string u_string_out = "";
|
||||
std::string u_string_out = "";
|
||||
for(size_t i=0;i<u_string.length();i++)
|
||||
{
|
||||
u_string_out += toupper(u_string[i]);
|
||||
@@ -478,7 +490,7 @@ inline string rc_intern_ucase(string u_string)
|
||||
return u_string_out;
|
||||
}
|
||||
|
||||
inline double rc_intern_val(string v_string)
|
||||
inline double rc_intern_val(std::string v_string)
|
||||
{
|
||||
return atof(v_string.c_str());
|
||||
}
|
||||
@@ -512,10 +524,10 @@ inline double rc_intern_aTan(double n)
|
||||
}
|
||||
|
||||
#ifdef RC_ANDROID
|
||||
string Convert(unsigned int val)
|
||||
std::string Convert(unsigned int val)
|
||||
{
|
||||
unsigned int mask = 1 << (sizeof(int) * 8 - 1);
|
||||
string binstr = "";
|
||||
std::string binstr = "";
|
||||
|
||||
for(int i = 0; i < sizeof(int) * 8; i++)
|
||||
{
|
||||
@@ -531,18 +543,18 @@ string Convert(unsigned int val)
|
||||
return binstr;
|
||||
}
|
||||
|
||||
inline string rc_intern_bin(uint64_t n)
|
||||
inline std::string rc_intern_bin(uint64_t n)
|
||||
{
|
||||
//string bin_str = bitset<64>(n).to_string();
|
||||
//bin_str = bin_str.substr(bin_str.find_first_not_of("0"));
|
||||
string binstr = Convert(n);// bin_str;
|
||||
std::string binstr = Convert(n);// bin_str;
|
||||
return binstr.substr(binstr.find_first_not_of("0"));
|
||||
}
|
||||
#else
|
||||
|
||||
inline string rc_intern_bin(uint64_t n)
|
||||
inline std::string rc_intern_bin(uint64_t n)
|
||||
{
|
||||
string bin_str = bitset<64>(n).to_string();
|
||||
std::string bin_str = bitset<64>(n).to_string();
|
||||
bin_str = bin_str.substr(bin_str.find_first_not_of("0"));
|
||||
return bin_str;
|
||||
}
|
||||
@@ -586,14 +598,14 @@ inline double rc_intern_frac(double n)
|
||||
return n - floor(n);
|
||||
}
|
||||
|
||||
inline string rc_intern_hex(uint64_t n)
|
||||
inline std::string rc_intern_hex(uint64_t n)
|
||||
{
|
||||
stringstream ss;
|
||||
ss << hex << n;
|
||||
return ss.str();
|
||||
}
|
||||
|
||||
inline double rc_intern_hexInt(string n)
|
||||
inline double rc_intern_hexInt(std::string n)
|
||||
{
|
||||
uint64_t x;
|
||||
stringstream ss;
|
||||
@@ -689,8 +701,18 @@ inline double rc_intern_xorbit(uint64_t a, uint64_t b)
|
||||
return (a ^ b);
|
||||
}
|
||||
|
||||
inline int rc_intern_fileOpen(int fo_stream, string fo_file, int fo_mode)
|
||||
inline int rc_intern_freeFile()
|
||||
{
|
||||
for(int i = 0; i < RC_MAX_FILES; i++)
|
||||
if(rc_fstream[i] == NULL)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
inline int rc_intern_fileOpen(std::string fo_file, int fo_mode)
|
||||
{
|
||||
int fo_stream = rc_intern_freeFile();
|
||||
|
||||
if(fo_stream >= 0 && fo_stream < RC_MAX_FILES)
|
||||
{
|
||||
if(rc_fstream[fo_stream] != NULL)
|
||||
@@ -742,10 +764,10 @@ inline int rc_intern_fileOpen(int fo_stream, string fo_file, int fo_mode)
|
||||
if(rc_fstream[fo_stream] == NULL)
|
||||
{
|
||||
//cout << "RC_DEBUG: FILE NOT OPEN" << endl;
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
return fo_stream;
|
||||
}
|
||||
|
||||
inline int rc_intern_fileClose(int fc_stream)
|
||||
@@ -802,9 +824,9 @@ inline int rc_intern_fileWriteByte(int f_stream, char wb)
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline string rc_intern_fileReadLine(int f_stream)
|
||||
inline std::string rc_intern_fileReadLine(int f_stream)
|
||||
{
|
||||
string rline = "";
|
||||
std::string rline = "";
|
||||
unsigned char buf[5];
|
||||
if(SDL_RWread(rc_fstream[f_stream], buf, 1, 1)==0)
|
||||
{
|
||||
@@ -826,7 +848,7 @@ inline string rc_intern_fileReadLine(int f_stream)
|
||||
return rline;
|
||||
}
|
||||
|
||||
inline int rc_intern_fileWrite(int f_stream, string line)
|
||||
inline int rc_intern_fileWrite(int f_stream, std::string line)
|
||||
{
|
||||
//cout << "DEBUG: WRITELINE" << endl;
|
||||
if(rc_fstream[f_stream]!=NULL)
|
||||
@@ -835,17 +857,17 @@ inline int rc_intern_fileWrite(int f_stream, string line)
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int rc_intern_fileWriteLine(int f_stream, string line)
|
||||
inline int rc_intern_fileWriteLine(int f_stream, std::string line)
|
||||
{
|
||||
//cout << "DEBUG: WRITELINE" << endl;
|
||||
string line_out = line + "\n";
|
||||
std::string line_out = line + "\n";
|
||||
if(rc_fstream[f_stream]!=NULL)
|
||||
SDL_RWwrite(rc_fstream[f_stream], line_out.c_str(), line_out.length(), 1);
|
||||
//cout << "WRITELINE_END" << endl;
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int rc_intern_fileCopy(string src_file, string dst_file)
|
||||
inline int rc_intern_fileCopy(std::string src_file, std::string dst_file)
|
||||
{
|
||||
std::ifstream src(src_file.c_str(), std::ios::binary);
|
||||
std::ofstream dst(dst_file.c_str(), std::ios::binary);
|
||||
@@ -863,7 +885,7 @@ inline int rc_intern_fileCopy(string src_file, string dst_file)
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int rc_intern_fileDelete(string tgt_file)
|
||||
inline int rc_intern_fileDelete(std::string tgt_file)
|
||||
{
|
||||
if(remove(tgt_file.c_str())==0)
|
||||
return 1;
|
||||
@@ -871,7 +893,7 @@ inline int rc_intern_fileDelete(string tgt_file)
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int rc_intern_fileExist(string tgt_file)
|
||||
inline int rc_intern_fileExist(std::string tgt_file)
|
||||
{
|
||||
std::ifstream infile(tgt_file.c_str());
|
||||
bool fx = infile.good();
|
||||
@@ -879,7 +901,7 @@ inline int rc_intern_fileExist(string tgt_file)
|
||||
return (int)fx;
|
||||
}
|
||||
|
||||
inline int rc_intern_fileMove(string src, string dst)
|
||||
inline int rc_intern_fileMove(std::string src, std::string dst)
|
||||
{
|
||||
int fm = rename(src.c_str(), dst.c_str());
|
||||
if(fm == 0)
|
||||
@@ -888,7 +910,7 @@ inline int rc_intern_fileMove(string src, string dst)
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline int rc_intern_fileRename(string src, string dst)
|
||||
inline int rc_intern_fileRename(std::string src, std::string dst)
|
||||
{
|
||||
int fm = rename(src.c_str(), dst.c_str());
|
||||
if(fm == 0)
|
||||
@@ -897,7 +919,7 @@ inline int rc_intern_fileRename(string src, string dst)
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline unsigned long rc_intern_fileLength(string filename)
|
||||
inline unsigned long rc_intern_fileLength(std::string filename)
|
||||
{
|
||||
//struct stat st;
|
||||
SDL_RWops * fl_file = SDL_RWFromFile(filename.c_str(), "r");
|
||||
@@ -925,18 +947,11 @@ inline int rc_intern_eof(int f_stream)
|
||||
return rc_eof[f_stream];
|
||||
}
|
||||
|
||||
inline int rc_intern_freeFile()
|
||||
{
|
||||
for(int i = 0; i < RC_MAX_FILES; i++)
|
||||
if(rc_fstream[i] == NULL)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
#ifndef RC_WINDOWS
|
||||
|
||||
#ifdef RC_LINUX
|
||||
inline int rc_intern_dirChange(string ch_path)
|
||||
inline int rc_intern_dirChange(std::string ch_path)
|
||||
{
|
||||
if(chdir(ch_path.c_str())!=0)
|
||||
{
|
||||
@@ -948,7 +963,7 @@ inline int rc_intern_dirChange(string ch_path)
|
||||
}
|
||||
#endif // RC_LINUX
|
||||
|
||||
inline int rc_intern_dirExist(string d_path)
|
||||
inline int rc_intern_dirExist(std::string d_path)
|
||||
{
|
||||
struct stat info;
|
||||
|
||||
@@ -960,7 +975,7 @@ inline int rc_intern_dirExist(string d_path)
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline string rc_intern_dirFirst ()
|
||||
inline std::string rc_intern_dirFirst ()
|
||||
{
|
||||
rc_dir = opendir (rc_dir_path.c_str());
|
||||
//string s = "";
|
||||
@@ -974,24 +989,24 @@ inline string rc_intern_dirFirst ()
|
||||
}
|
||||
|
||||
#ifdef RC_GETCWD
|
||||
string getcwd_str()
|
||||
std::string getcwd_str()
|
||||
{
|
||||
char *buffer = new char[MAXPATHLEN];
|
||||
getcwd(buffer,MAXPATHLEN);
|
||||
if(buffer != NULL)
|
||||
{
|
||||
string ret(buffer);
|
||||
std::string ret(buffer);
|
||||
delete[] buffer;
|
||||
return ret;
|
||||
}
|
||||
else
|
||||
{
|
||||
return string();
|
||||
return std::string();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline int rc_intern_dirChange(string ch_path)
|
||||
inline int rc_intern_dirChange(std::string ch_path)
|
||||
{
|
||||
if(chdir(ch_path.c_str())!=0)
|
||||
{
|
||||
@@ -1002,9 +1017,9 @@ inline int rc_intern_dirChange(string ch_path)
|
||||
return 0;
|
||||
}
|
||||
|
||||
inline string rc_intern_dir()
|
||||
inline std::string rc_intern_dir()
|
||||
{
|
||||
string d = getcwd_str();
|
||||
std::string d = getcwd_str();
|
||||
//__android_log_print(ANDROID_LOG_ERROR, "RC_DEBUG_DIR", "%s", SDL_GetPrefPath("rcbasic","lucky"));
|
||||
if(d.compare("")==0)
|
||||
{
|
||||
@@ -1017,9 +1032,9 @@ inline string rc_intern_dir()
|
||||
|
||||
#else
|
||||
|
||||
inline string rc_intern_dir()
|
||||
inline std::string rc_intern_dir()
|
||||
{
|
||||
string d = get_current_dir_name();
|
||||
std::string d = get_current_dir_name();
|
||||
if(d.compare("")==0)
|
||||
{
|
||||
cout << "Could not get current directory" << endl;
|
||||
@@ -1031,14 +1046,14 @@ inline string rc_intern_dir()
|
||||
|
||||
#endif // RC_ANDROID
|
||||
|
||||
inline string rc_intern_dirNext()
|
||||
inline std::string rc_intern_dirNext()
|
||||
{
|
||||
if( (rc_entry = readdir(rc_dir))!=NULL)
|
||||
return rc_entry->d_name;
|
||||
return "";
|
||||
}
|
||||
|
||||
inline int rc_intern_dirCreate(string d_path)
|
||||
inline int rc_intern_dirCreate(std::string d_path)
|
||||
{
|
||||
if(mkdir(d_path.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)!=0)
|
||||
{
|
||||
@@ -1048,7 +1063,7 @@ inline int rc_intern_dirCreate(string d_path)
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int rc_intern_dirDelete(string d_path)
|
||||
inline int rc_intern_dirDelete(std::string d_path)
|
||||
{
|
||||
if(rmdir(d_path.c_str())!=0)
|
||||
{
|
||||
@@ -1058,7 +1073,7 @@ inline int rc_intern_dirDelete(string d_path)
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline string rc_intern_OS()
|
||||
inline std::string rc_intern_OS()
|
||||
{
|
||||
#ifdef RC_WEB
|
||||
return "WEB";
|
||||
@@ -1115,7 +1130,7 @@ std::wstring ConvertUtf8ToWide(const std::string& str)
|
||||
return wstr;
|
||||
}
|
||||
|
||||
inline int rc_intern_dirChange(string dpath)
|
||||
inline int rc_intern_dirChange(std::string dpath)
|
||||
{
|
||||
if(SetCurrentDirectoryW(ConvertUtf8ToWide(dpath).c_str())==0)
|
||||
{
|
||||
@@ -1144,7 +1159,7 @@ bool dirExists(const std::string& dirName_in)
|
||||
return false; // this is not a directory!
|
||||
}
|
||||
|
||||
inline int rc_intern_dirExist(string dpath)
|
||||
inline int rc_intern_dirExist(std::string dpath)
|
||||
{
|
||||
return dirExists(dpath);
|
||||
}
|
||||
@@ -1152,7 +1167,7 @@ inline int rc_intern_dirExist(string dpath)
|
||||
HANDLE hFind;
|
||||
WIN32_FIND_DATAW ffd;
|
||||
|
||||
string rc_intern_dirFirst()
|
||||
std::string rc_intern_dirFirst()
|
||||
{
|
||||
|
||||
//char* path = new char[rc_dir_path.length()+1];
|
||||
@@ -1168,7 +1183,7 @@ string rc_intern_dirFirst()
|
||||
//_tcscat(path, _T("*.*"));
|
||||
|
||||
|
||||
string path = rc_dir_path;
|
||||
std::string path = rc_dir_path;
|
||||
|
||||
if(path.substr(path.length()-1, 1).compare("\\")!=0)
|
||||
path += "\\";
|
||||
@@ -1185,11 +1200,11 @@ string rc_intern_dirFirst()
|
||||
cerr << _T("Invalid handle value.") << GetLastError() << endl;
|
||||
return "";
|
||||
}
|
||||
string fname_utf8 = ConvertWideToUtf8(ffd.cFileName);
|
||||
std::string fname_utf8 = ConvertWideToUtf8(ffd.cFileName);
|
||||
return fname_utf8;
|
||||
}
|
||||
|
||||
inline string rc_intern_dir()
|
||||
inline std::string rc_intern_dir()
|
||||
{
|
||||
wchar_t buf[MAX_PATH+1];
|
||||
GetCurrentDirectoryW(MAX_PATH, buf);
|
||||
@@ -1204,14 +1219,14 @@ inline string rc_intern_dir()
|
||||
return ConvertWideToUtf8(d.c_str());
|
||||
}
|
||||
|
||||
string rc_intern_dirNext()
|
||||
std::string rc_intern_dirNext()
|
||||
{
|
||||
if(!FindNextFileW(hFind,&ffd))
|
||||
return "";
|
||||
return ConvertWideToUtf8(ffd.cFileName);
|
||||
}
|
||||
|
||||
inline int rc_intern_dirCreate(string dpath)
|
||||
inline int rc_intern_dirCreate(std::string dpath)
|
||||
{
|
||||
if(CreateDirectoryW(ConvertUtf8ToWide(dpath).c_str(),NULL)==0)
|
||||
{
|
||||
@@ -1221,7 +1236,7 @@ inline int rc_intern_dirCreate(string dpath)
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int rc_intern_dirDelete(string dpath)
|
||||
inline int rc_intern_dirDelete(std::string dpath)
|
||||
{
|
||||
if(RemoveDirectoryW(ConvertUtf8ToWide(dpath).c_str())==0)
|
||||
{
|
||||
@@ -1231,7 +1246,7 @@ inline int rc_intern_dirDelete(string dpath)
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline string rc_intern_OS()
|
||||
inline std::string rc_intern_OS()
|
||||
{
|
||||
return "WINDOWS";
|
||||
}
|
||||
@@ -1239,7 +1254,7 @@ inline string rc_intern_OS()
|
||||
#endif // RC_WINDOWS
|
||||
|
||||
|
||||
inline string rc_intern_date()
|
||||
inline std::string rc_intern_date()
|
||||
{
|
||||
time_t t = time(0); // get time now
|
||||
struct tm * now = localtime( & t );
|
||||
@@ -1256,12 +1271,12 @@ inline string rc_intern_date()
|
||||
return d.str();
|
||||
}
|
||||
|
||||
string ZeroPadNumber(int num)
|
||||
std::string ZeroPadNumber(int num)
|
||||
{
|
||||
stringstream ss;
|
||||
// the number is converted to string with the help of stringstream
|
||||
ss << num;
|
||||
string ret;
|
||||
std::string ret;
|
||||
ss >> ret;
|
||||
// Append zero chars
|
||||
int str_length = ret.length();
|
||||
@@ -1270,7 +1285,7 @@ string ZeroPadNumber(int num)
|
||||
return ret;
|
||||
}
|
||||
|
||||
string rc_intern_easter(int X)
|
||||
std::string rc_intern_easter(int X)
|
||||
{
|
||||
stringstream ss; // X = year to compute
|
||||
int K, M, S, A, D, R, OG, SZ, OE;
|
||||
@@ -1293,7 +1308,7 @@ inline unsigned long rc_intern_ticks()
|
||||
return clock();
|
||||
}
|
||||
|
||||
inline string rc_intern_time()
|
||||
inline std::string rc_intern_time()
|
||||
{
|
||||
time_t t = time(0); // get time now
|
||||
struct tm * now = localtime( & t );
|
||||
@@ -1326,7 +1341,7 @@ inline void rc_intern_wait(double m_sec)
|
||||
SDL_Delay(m_sec);
|
||||
}
|
||||
|
||||
inline int rc_intern_system(string rc_sys_cmd)
|
||||
inline int rc_intern_system(std::string rc_sys_cmd)
|
||||
{
|
||||
#ifdef RC_IOS
|
||||
return 0;
|
||||
@@ -1335,7 +1350,7 @@ inline int rc_intern_system(string rc_sys_cmd)
|
||||
#endif
|
||||
}
|
||||
|
||||
inline string rc_intern_sysReturnOutput(string rc_sys_cmd)
|
||||
inline std::string rc_intern_sysReturnOutput(std::string rc_sys_cmd)
|
||||
{
|
||||
#if defined(RC_ANDROID) || defined(RC_IOS) || defined(RC_WEB)
|
||||
return "";
|
||||
@@ -1358,7 +1373,7 @@ inline string rc_intern_sysReturnOutput(string rc_sys_cmd)
|
||||
#endif
|
||||
}
|
||||
|
||||
inline string rc_intern_command(int num)
|
||||
inline std::string rc_intern_command(int num)
|
||||
{
|
||||
if(num < rc_cmd_count)
|
||||
{
|
||||
@@ -1372,25 +1387,25 @@ inline int rc_intern_numCommands()
|
||||
return rc_cmd_count;
|
||||
}
|
||||
|
||||
inline string rc_intern_env(string v)
|
||||
inline std::string rc_intern_env(std::string v)
|
||||
{
|
||||
#ifdef RC_WINDOWS
|
||||
char * val = new char[32767];
|
||||
int n = GetEnvironmentVariable(v.c_str(), val, 32767);
|
||||
string rtn = "";
|
||||
std::string rtn = "";
|
||||
if (n>0)
|
||||
rtn = (string)val;
|
||||
rtn = (std::string)val;
|
||||
delete val;
|
||||
return rtn;
|
||||
#else
|
||||
char * c = getenv(v.c_str());
|
||||
if(c != NULL)
|
||||
return (string) c;
|
||||
return (std::string) c;
|
||||
return "";
|
||||
#endif
|
||||
}
|
||||
|
||||
inline int rc_intern_setEnv(string name, string value, int overwrite)
|
||||
inline int rc_intern_setEnv(std::string name, std::string value, int overwrite)
|
||||
{
|
||||
#ifdef RC_WINDOWS
|
||||
//string env_cmd = name + "=" + value;
|
||||
@@ -1401,45 +1416,126 @@ inline int rc_intern_setEnv(string name, string value, int overwrite)
|
||||
#endif
|
||||
}
|
||||
|
||||
inline string rc_intern_prefPath(string org_name, string app_name)
|
||||
inline std::string rc_intern_prefPath(std::string org_name, std::string app_name)
|
||||
{
|
||||
return (string) SDL_GetPrefPath(org_name.c_str(), app_name.c_str());
|
||||
return (std::string) SDL_GetPrefPath(org_name.c_str(), app_name.c_str());
|
||||
}
|
||||
|
||||
inline int rc_intern_push_n(double n)
|
||||
|
||||
inline int rc_intern_createStack_N()
|
||||
{
|
||||
rc_user_n_stack[rc_user_active_n_stack].push(n);
|
||||
return 1;
|
||||
int id = -1;
|
||||
for(int i = 0; i < rc_user_n_stack.size(); i++)
|
||||
{
|
||||
if(!rc_user_n_stack[i].active)
|
||||
{
|
||||
id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(id < 0)
|
||||
{
|
||||
rc_num_stack_obj usr_stack;
|
||||
usr_stack.active = true;
|
||||
id = rc_user_n_stack.size();
|
||||
rc_user_n_stack.push_back(usr_stack);
|
||||
}
|
||||
else
|
||||
{
|
||||
while(!rc_user_n_stack[id].data.empty())
|
||||
rc_user_n_stack[id].data.pop();
|
||||
rc_user_n_stack[id].active = true;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
inline int rc_intern_push_s(string s)
|
||||
inline int rc_intern_createStack_S()
|
||||
{
|
||||
rc_user_s_stack[rc_user_active_s_stack].push(s);
|
||||
return 1;
|
||||
int id = -1;
|
||||
for(int i = 0; i < rc_user_s_stack.size(); i++)
|
||||
{
|
||||
if(!rc_user_s_stack[i].active)
|
||||
{
|
||||
id = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(id < 0)
|
||||
{
|
||||
rc_str_stack_obj usr_stack;
|
||||
usr_stack.active = true;
|
||||
id = rc_user_s_stack.size();
|
||||
rc_user_s_stack.push_back(usr_stack);
|
||||
}
|
||||
else
|
||||
{
|
||||
while(!rc_user_s_stack[id].data.empty())
|
||||
rc_user_s_stack[id].data.pop();
|
||||
rc_user_s_stack[id].active = true;
|
||||
}
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
inline double rc_intern_pop_n()
|
||||
inline void rc_intern_clearStack_N( int stack_id )
|
||||
{
|
||||
double n = rc_user_n_stack[rc_user_active_n_stack].top();
|
||||
rc_user_n_stack[rc_user_active_n_stack].pop();
|
||||
while(!rc_user_n_stack[stack_id].data.empty())
|
||||
rc_user_n_stack[stack_id].data.pop();
|
||||
}
|
||||
|
||||
inline void rc_intern_clearStack_S( int stack_id )
|
||||
{
|
||||
while(!rc_user_s_stack[stack_id].data.empty())
|
||||
rc_user_s_stack[stack_id].data.pop();
|
||||
}
|
||||
|
||||
inline void rc_intern_deleteStack_N( int stack_id )
|
||||
{
|
||||
rc_intern_clearStack_N(stack_id);
|
||||
rc_user_n_stack[stack_id].active = false;
|
||||
}
|
||||
|
||||
inline void rc_intern_deleteStack_S( int stack_id )
|
||||
{
|
||||
rc_intern_clearStack_S(stack_id);
|
||||
rc_user_s_stack[stack_id].active = false;
|
||||
}
|
||||
|
||||
inline void rc_intern_push_n( int stack_id, double n)
|
||||
{
|
||||
rc_user_n_stack[stack_id].data.push(n);
|
||||
}
|
||||
|
||||
inline void rc_intern_push_s( int stack_id, std::string s)
|
||||
{
|
||||
rc_user_s_stack[stack_id].data.push(s);
|
||||
}
|
||||
|
||||
inline double rc_intern_pop_n( int stack_id )
|
||||
{
|
||||
double n = rc_user_n_stack[stack_id].data.top();
|
||||
rc_user_n_stack[stack_id].data.pop();
|
||||
return n;
|
||||
}
|
||||
|
||||
inline string rc_intern_pop_s()
|
||||
inline std::string rc_intern_pop_s( int stack_id )
|
||||
{
|
||||
string s = rc_user_s_stack[rc_user_active_s_stack].top();
|
||||
rc_user_s_stack[rc_user_active_s_stack].pop();
|
||||
std::string s = rc_user_s_stack[stack_id].data.top();
|
||||
rc_user_s_stack[stack_id].data.pop();
|
||||
return s;
|
||||
}
|
||||
|
||||
inline unsigned long rc_intern_n_stack_size()
|
||||
inline unsigned long rc_intern_n_stack_size( int stack_id )
|
||||
{
|
||||
return rc_user_n_stack[rc_user_active_n_stack].size();
|
||||
return rc_user_n_stack[stack_id].data.size();
|
||||
}
|
||||
|
||||
inline unsigned long rc_intern_s_stack_size()
|
||||
inline unsigned long rc_intern_s_stack_size( int stack_id )
|
||||
{
|
||||
return rc_user_s_stack[rc_user_active_s_stack].size();
|
||||
return rc_user_s_stack[stack_id].data.size();
|
||||
}
|
||||
|
||||
inline void rc_intern_getPowerInfo(double * status, double * secs, double * pct)
|
||||
@@ -1469,12 +1565,12 @@ int rc_intern_systemRam()
|
||||
}
|
||||
|
||||
#ifdef RC_WEB
|
||||
string rc_intern_evalJS(string js_code)
|
||||
std::string rc_intern_evalJS(std::string js_code)
|
||||
{
|
||||
return emscripten_run_script_string(js_code.c_str());
|
||||
}
|
||||
#else
|
||||
string rc_intern_evalJS(string js_code)
|
||||
std::string rc_intern_evalJS(std::string js_code)
|
||||
{
|
||||
return "ONLY IN WEB";
|
||||
}
|
||||
@@ -1482,7 +1578,7 @@ string rc_intern_evalJS(string js_code)
|
||||
|
||||
|
||||
//MOBILE OS STUFF
|
||||
inline string rc_intern_android_getInternalStoragePath()
|
||||
inline std::string rc_intern_android_getInternalStoragePath()
|
||||
{
|
||||
#ifdef RC_ANDROID
|
||||
return SDL_AndroidGetInternalStoragePath();
|
||||
@@ -1491,7 +1587,7 @@ inline string rc_intern_android_getInternalStoragePath()
|
||||
#endif
|
||||
}
|
||||
|
||||
inline string rc_intern_android_getExternalStoragePath()
|
||||
inline std::string rc_intern_android_getExternalStoragePath()
|
||||
{
|
||||
#ifdef RC_ANDROID
|
||||
return SDL_AndroidGetExternalStoragePath();
|
||||
@@ -1509,7 +1605,7 @@ inline int rc_intern_android_getExternalStorageState()
|
||||
#endif
|
||||
}
|
||||
|
||||
string rc_intern_android_jni_message(string arg_c)
|
||||
std::string rc_intern_android_jni_message(std::string arg_c)
|
||||
{
|
||||
#ifdef RC_ANDROID
|
||||
|
||||
@@ -1537,7 +1633,7 @@ string rc_intern_android_jni_message(string arg_c)
|
||||
env->DeleteLocalRef(activity);
|
||||
env->DeleteLocalRef(clazz);
|
||||
|
||||
return (string)strReturn;
|
||||
return (std::string)strReturn;
|
||||
|
||||
#else
|
||||
return "";
|
||||
@@ -1547,7 +1643,7 @@ string rc_intern_android_jni_message(string arg_c)
|
||||
#ifdef RC_IOS
|
||||
#include "rcbasic_ios_native.h"
|
||||
#else
|
||||
string rc_intern_runtime_utility(string arg)
|
||||
std::string rc_intern_runtime_utility(std::string arg)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
107
rcbasic_runtime/rc_steam.cpp
Executable file
107
rcbasic_runtime/rc_steam.cpp
Executable file
@@ -0,0 +1,107 @@
|
||||
#include "rc_steam.h"
|
||||
|
||||
CSteamAchievements::CSteamAchievements(Achievement_t *Achievements, int NumAchievements):
|
||||
m_iAppID( 0 ),
|
||||
m_bInitialized( false ),
|
||||
m_CallbackUserStatsReceived( this, &CSteamAchievements::OnUserStatsReceived ),
|
||||
m_CallbackUserStatsStored( this, &CSteamAchievements::OnUserStatsStored ),
|
||||
m_CallbackAchievementStored( this, &CSteamAchievements::OnAchievementStored )
|
||||
{
|
||||
m_iAppID = SteamUtils()->GetAppID();
|
||||
m_pAchievements = Achievements;
|
||||
m_iNumAchievements = NumAchievements;
|
||||
RequestStats();
|
||||
}
|
||||
|
||||
|
||||
bool CSteamAchievements::RequestStats()
|
||||
{
|
||||
// Is Steam loaded? If not we can't get stats.
|
||||
if ( NULL == SteamUserStats() || NULL == SteamUser() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Is the user logged on? If not we can't get stats.
|
||||
if ( !SteamUser()->BLoggedOn() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
// Request user stats.
|
||||
return SteamUserStats()->RequestCurrentStats();
|
||||
}
|
||||
|
||||
|
||||
bool CSteamAchievements::SetAchievement(const char* ID)
|
||||
{
|
||||
// Have we received a call back from Steam yet?
|
||||
if (m_bInitialized)
|
||||
{
|
||||
SteamUserStats()->SetAchievement(ID);
|
||||
return SteamUserStats()->StoreStats();
|
||||
}
|
||||
// If not then we can't set achievements yet
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
void CSteamAchievements::OnUserStatsReceived( UserStatsReceived_t *pCallback )
|
||||
{
|
||||
// we may get callbacks for other games' stats arriving, ignore them
|
||||
if ( m_iAppID == pCallback->m_nGameID )
|
||||
{
|
||||
if ( k_EResultOK == pCallback->m_eResult )
|
||||
{
|
||||
OutputDebugString("Received stats and achievements from Steam\n");
|
||||
m_bInitialized = true;
|
||||
|
||||
// load achievements
|
||||
for ( int iAch = 0; iAch < m_iNumAchievements; ++iAch )
|
||||
{
|
||||
Achievement_t &ach = m_pAchievements[iAch];
|
||||
|
||||
SteamUserStats()->GetAchievement(ach.m_pchAchievementID, &ach.m_bAchieved);
|
||||
_snprintf( ach.m_rgchName, sizeof(ach.m_rgchName), "%s",
|
||||
SteamUserStats()->GetAchievementDisplayAttribute(ach.m_pchAchievementID,
|
||||
"name"));
|
||||
_snprintf( ach.m_rgchDescription, sizeof(ach.m_rgchDescription), "%s",
|
||||
SteamUserStats()->GetAchievementDisplayAttribute(ach.m_pchAchievementID,
|
||||
"desc"));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
char buffer[128];
|
||||
_snprintf( buffer, 128, "RequestStats - failed, %d\n", pCallback->m_eResult );
|
||||
OutputDebugString( buffer );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CSteamAchievements::OnUserStatsStored( UserStatsStored_t *pCallback )
|
||||
{
|
||||
// we may get callbacks for other games' stats arriving, ignore them
|
||||
if ( m_iAppID == pCallback->m_nGameID )
|
||||
{
|
||||
if ( k_EResultOK == pCallback->m_eResult )
|
||||
{
|
||||
OutputDebugString( "Stored stats for Steam\n" );
|
||||
}
|
||||
else
|
||||
{
|
||||
char buffer[128];
|
||||
_snprintf( buffer, 128, "StatsStored - failed, %d\n", pCallback->m_eResult );
|
||||
OutputDebugString( buffer );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void CSteamAchievements::OnAchievementStored( UserAchievementStored_t *pCallback )
|
||||
{
|
||||
// we may get callbacks for other games' stats arriving, ignore them
|
||||
if ( m_iAppID == pCallback->m_nGameID )
|
||||
{
|
||||
OutputDebugString( "Stored Achievement for Steam\n" );
|
||||
}
|
||||
}
|
||||
46
rcbasic_runtime/rc_steam.h
Executable file
46
rcbasic_runtime/rc_steam.h
Executable file
@@ -0,0 +1,46 @@
|
||||
#ifndef RC_STEAM_H_INCLUDED
|
||||
#define RC_STEAM_H_INCLUDED
|
||||
|
||||
#include <steam/steam_api.h>
|
||||
|
||||
#define _ACH_ID( id, name ) { id, #id, name, "", 0, 0 }
|
||||
struct Achievement_t
|
||||
{
|
||||
int m_eAchievementID;
|
||||
const char *m_pchAchievementID;
|
||||
char m_rgchName[128];
|
||||
char m_rgchDescription[256];
|
||||
bool m_bAchieved;
|
||||
int m_iIconImage;
|
||||
};
|
||||
|
||||
|
||||
class CSteamAchievements
|
||||
{
|
||||
private:
|
||||
int64 m_iAppID; // Our current AppID
|
||||
Achievement_t *m_pAchievements; // Achievements data
|
||||
int m_iNumAchievements; // The number of Achievements
|
||||
bool m_bInitialized; // Have we called Request stats and received the callback?
|
||||
|
||||
public:
|
||||
CSteamAchievements(Achievement_t *Achievements, int NumAchievements);
|
||||
~CSteamAchievements();
|
||||
|
||||
bool RequestStats();
|
||||
bool SetAchievement(const char* ID);
|
||||
|
||||
STEAM_CALLBACK( CSteamAchievements, OnUserStatsReceived, UserStatsReceived_t,
|
||||
m_CallbackUserStatsReceived );
|
||||
STEAM_CALLBACK( CSteamAchievements, OnUserStatsStored, UserStatsStored_t,
|
||||
m_CallbackUserStatsStored );
|
||||
STEAM_CALLBACK( CSteamAchievements, OnAchievementStored,
|
||||
UserAchievementStored_t, m_CallbackAchievementStored );
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // RC_STEAM_H_INCLUDED
|
||||
22
rcbasic_runtime/rc_steam_lib.h
Executable file
22
rcbasic_runtime/rc_steam_lib.h
Executable file
@@ -0,0 +1,22 @@
|
||||
#include <steam/steam_api.h>
|
||||
|
||||
// Defining our achievements
|
||||
enum EAchievements
|
||||
{
|
||||
ACH_WIN_ONE_GAME = 0,
|
||||
ACH_WIN_100_GAMES = 1,
|
||||
ACH_TRAVEL_FAR_ACCUM = 2,
|
||||
ACH_TRAVEL_FAR_SINGLE = 3,
|
||||
};
|
||||
|
||||
// Achievement array which will hold data about the achievements and their state
|
||||
Achievement_t g_Achievements[] =
|
||||
{
|
||||
_ACH_ID( ACH_WIN_ONE_GAME, "Winner" ),
|
||||
_ACH_ID( ACH_WIN_100_GAMES, "Champion" ),
|
||||
_ACH_ID( ACH_TRAVEL_FAR_ACCUM, "Interstellar" ),
|
||||
_ACH_ID( ACH_TRAVEL_FAR_SINGLE, "Orbiter" ),
|
||||
};
|
||||
|
||||
// Global access to Achievements object
|
||||
CSteamAchievements* g_SteamAchievements = NULL;
|
||||
45
rcbasic_runtime/rc_utf8.h
Normal file
45
rcbasic_runtime/rc_utf8.h
Normal file
@@ -0,0 +1,45 @@
|
||||
#ifndef RC_UTF8_H_INCLUDED
|
||||
#define RC_UTF8_H_INCLUDED
|
||||
|
||||
#include <string>
|
||||
#include <algorithm>
|
||||
|
||||
std::string rc_utf8_substr(const std::string& str, unsigned int start, unsigned int leng)
|
||||
{
|
||||
if (leng==0) { return ""; }
|
||||
unsigned int c, i, ix, q, min=std::string::npos, max=std::string::npos;
|
||||
for (q=0, i=0, ix=str.length(); i < ix; i++, q++)
|
||||
{
|
||||
if (q==start){ min=i; }
|
||||
if (q<=start+leng || leng==std::string::npos){ max=i; }
|
||||
|
||||
c = (unsigned char) str[i];
|
||||
if (
|
||||
//c>=0 &&
|
||||
c<=127) i+=0;
|
||||
else if ((c & 0xE0) == 0xC0) i+=1;
|
||||
else if ((c & 0xF0) == 0xE0) i+=2;
|
||||
else if ((c & 0xF8) == 0xF0) i+=3;
|
||||
//else if (($c & 0xFC) == 0xF8) i+=4; // 111110bb //byte 5, unnecessary in 4 byte UTF-8
|
||||
//else if (($c & 0xFE) == 0xFC) i+=5; // 1111110b //byte 6, unnecessary in 4 byte UTF-8
|
||||
else return "";//invalid utf8
|
||||
}
|
||||
if (q<=start+leng || leng==std::string::npos){ max=i; }
|
||||
if (min==std::string::npos || max==std::string::npos) { return ""; }
|
||||
return str.substr(min,max-min);
|
||||
}
|
||||
|
||||
std::size_t rc_utf8_length(std::string const &s)
|
||||
{
|
||||
return std::count_if(s.begin(), s.end(),
|
||||
[](char c) { return (static_cast<unsigned char>(c) & 0xC0) != 0x80; } );
|
||||
}
|
||||
|
||||
// convert UTF-8 string to wstring
|
||||
std::wstring utf8_to_wstring (const std::string& str)
|
||||
{
|
||||
std::wstring_convert<std::codecvt_utf8<wchar_t>> myconv;
|
||||
return myconv.from_bytes(str);
|
||||
}
|
||||
|
||||
#endif // RC_UTF8_H_INCLUDED
|
||||
Reference in New Issue
Block a user