In SDL 1.2, there is SDL_HasMMXExt. See here. The full source of the file can be seen here.
In SDL 2, that function is missing. Why? The full source of SDL2 of the same file can be seen here.
Relevant code of SDL 1.2 is this:
static __inline__ int CPU_haveMMX(void)
{
if ( CPU_haveCPUID() ) {
return (CPU_getCPUIDFeatures() & 0x00800000);
}
return 0;
}
static __inline__ int CPU_haveMMXExt(void)
{
if ( CPU_haveCPUID() ) {
return (CPU_getCPUIDFeaturesExt() & 0x00400000);
}
return 0;
}
CPU_getCPUIDFeaturesExt is also missing in SDL2.
Why was it removed?
Related
I'm attempting to refactor my code using clang-tidy and it flags a number of changes that should not be applied. For example, I've defined for my cpp files the format:
{ key: readability-identifier-naming.FunctionCase, value: camelBack }
But it flags fixes for functions outside my control like
static void from_json(const nlohmann::json& aJson,...)
Everything I'm working with is contained within a namespace, so is it possible to only apply readability-identifier-naming to content within a namespace? Can this be done with existing functions or will I need to define my own format checker in the clang-tools-extra?
Update
I solved the issue by modifying IdentifierNamingCheck::getDeclFailureInfo and adding a namespace filter to the FileStyle. I pulled some code from another place. It's not a general solution but it works in my case.
// ...
if (!FileStyle.namespaceFilter().empty()) {
auto testNamespace = [&FileStyle](const DeclContext *DC) {
if (!DC->isNamespace())
return false;
const auto *ND = cast<NamespaceDecl>(DC);
if (ND->isInline()) {
return false;
}
if (!DC->getParent()->getRedeclContext()->isTranslationUnit())
return false;
const IdentifierInfo *II = ND->getIdentifier();
return II && II->isStr(FileStyle.namespaceFilter());
};
bool isNamespace = false;
for (const DeclContext *DC = Decl->getDeclContext(); DC;
DC = DC->getParent()) {
isNamespace |= testNamespace(DC);
if (isNamespace)
break;
}
if (!isNamespace)
return llvm::None;
}
// ...
I'm currently working on a project with MFC and I noticed something weird that apparently has been there for a couple of years. When I launch the .exe of the program, it will do n number of things including reading a .DAT file and storing it as well. If the file doesn't exists, the program will try to find it with no luck throwing this CFile exception: The file could not be located. Which is correct because it doesn't exists. I have to do some operations first to generate that file, the storing process works fine. When the file exists and I run the program again, it's supposed read the file but this CArchive exception shows up: Invalid file format. And I don't understand why.
This is the Serialize():
//Fruits.cpp
void CFruits::Serialize(CArchive &ar)
{
int nVersion = 0;
CObject::Serialize(ar);
ar.SerializeClass(GetRuntimeClass());
if(ar.IsStoring())
{
ar.Write(&m_bInit,sizeof(bool));
ar.Write(&m_bYummy,sizeof(bool));
ar.Write(&m_bAcid, sizeof(bool));
ar.Write(&m_bFresh,sizeof(bool));
...
...
...
ar<<m_cType;
ar<<m_cColour;
ar<<m_cFlavor;
ar<<m_cPrice;
ar<<m_cQuantity;
}
else
{
nVersion = ar.GetObjectSchema();
ar.Read(&m_bInit,sizeof(bool));
ar.Read(&m_bYummy,sizeof(bool));
ar.Read(&m_bAcid, sizeof(bool));
ar.Read(&m_bFresh,sizeof(bool));
...
...
...
if( nVersion >= 2 || nVersion < 0)
ar<<m_cType;
else
m_cType=0;
if (nVersion >= 3 || nVersion < 0)
ar<<m_cColour;
else
m_cColour=0;
if (nVersion >= 4 || nVersion < 0)
ar<<m_cFlavor;
else
ar<<m_cFlavor=0;
if( nVersion >= 5 || nVersion < 0)
{
ar<<m_cPrice;
ar<<m_cQuantity;
}
else
{
m_cPrice=0;
m_cQuantity=0;
}
}
m_oSales.Serialize(ar);
m_oAdmin.Serialize(ar);
...
...
}
IMPLEMENT_SERIAL(CVehiculo,CObject,VERSIONABLE_SCHEMA | 6)
This is the SerializeElements:
//Fruits.cpp
void AFXAPI SerializeElements(CArchive &ar,CFruits * fruits,int ncount)
{
try
{
for(cont=0;cont<ncount;cont++)
fruits[cont].Serialize(ar);
}
catch(CArchiveException *AE)
{
//Here it stores the exception in a Log. Exception 5
}
}
The serializeElements is used to store and read the file n times, as declared here in the header file of fruits:
//Fruits.h
class CFruits : public CObject
{
public:
CFruits();
CFruits(const CFruits &O);
virtual ~CFruits();
void operator = (const CFruits &O);
void Serialize(CArchive &ar);
protected:
DECLARE_SERIAL(CFruits)
};
void AFXAPI SerializeElements(CArchive &ar,CFruits * fruits,int ncount);
typedef CArray<CFruits, CFruitso&> TArrayFruits;
The values of this Array, and the methods used to call the serialize are defined here in my main function:
//main.h
#include "CFruits.h"
class CMain : public CDialog
{
// Construction
public:
enum T_Fruits { eFruitsOnLine, eFruitsIng, eFruitsTra, eFruitsAnt, eFruitsP3, eFruitsP2, eFruitsP1, eFruitsC1, eFruitsC0, eFruitsEscape, eFruitsVideo};
private:
void StoreFruits();
void ReadFruits();
The SerializeElements for-loop is supposed to run 11 times, but I noticed that it only does it 1 time, then the Schema version changes to -1, (originally 6 cause I managed to trace the value). This happens only when reading the file.
I've tried the following:
I can't use debug so I have to use Logs, I placed a Log after every sentence in the Serialize() function, I found what seems to be the issue, this line:
ar.SerializeClass(GetRuntimeClass());
I used a try-catch and found that when that sentence happens, it throws the exception so, it doesn't continue reading. That is the moment where the version changes to -1. I tried to change that to:
ar.SerializeClass(RUNTIME_CLASS(CFruits));
Is the same result, I've read many forums trying to find the answer but I can't seem to do so. I've read the documentation and I found this here:
https://learn.microsoft.com/en-us/cpp/mfc/reference/carchive-class?view=vs-2019#serializeclass
Like ReadClass, SerializeClass verifies that the archived class
information is compatible with your runtime class. If it is not
compatible, SerializeClass will throw a CArchiveException.
But it doesn't make sense to me, because it doesn't fail storing. Should I look into something else?
Thank you
EDIT:
I'm posting the Store and Read methods
void CMain::ReadFruits()
{
CString CSerror, sFileName;
CString sDebug;
try
{
sFileName.Format("FRUITS%03d.DAT",GetNumT());
CFile fFruitsTag(sFileName,CFile::modeRead);
CArchive ar(&fFruitsTag,CArchive::load);
m_vFruits.Serialize(ar);
ar.Close();
fFruitsTag.Close();
}
catch(CFileException *FE)
{
...
}
catch(CArchiveException *AE)
{
...
}
}
void CMain::StoreFruits()
{
CString CSerror, sFileName;
try
{
if(!m_bStoringFruits)
{
sFileName.Format("FRUITS%03d.DAT",GetNumT());
m_bStoringFruits=true;
CFile fFruitsTag(sFileName,CFile::modeCreate|CFile::modeWrite);
CArchive ar(&fFruitsTag,CArchive::store);
m_vFruits.Serialize(ar);
ar.Close();
fFruitsTag.Close();
m_bStoringFruits=false;
}
}
catch(CFileException *FE)
{
...
}
catch(CArchiveException *AE)
{
...
}
catch(CException *e)
{
...
}
}
I have written a C++ method from which I need to return a structure to Python.
I'm already able to send an OpenCV mat from Python to C++ using BOOST following the method described in this link.
Now I need to go the other way; return from C++ to Python, and then access that structure in Python. Can it be done?
Any samples or reference links would be good. I have tried googling before posting this question and I couldn't get any samples or explanation links.
You can use another function from modules/python/src2/cv2.cpp:
PyObject* pyopencv_from(const cv::Mat& m)
{
if( !m.data )
Py_RETURN_NONE;
cv::Mat temp, *p = (cv::Mat*)&m;
if(!p->refcount || p->allocator != &g_numpyAllocator)
{
temp.allocator = &g_numpyAllocator;
m.copyTo(temp);
p = &temp;
}
p->addref();
return pyObjectFromRefcount(p->refcount);
}
Then the Boost Python wrapper will look like:
boost::python::object toPython( const cv::Mat &frame )
{
PyObject* pyObjFrame = pyopencv_from( frame );
boost::python::object boostPyObjFrame(boost::python::handle<>((PyObject*)pyObjFrame));
return boostPyObjFrame;
}
Please have a look at this link: https://wiki.python.org/moin/boost.python/handle to make sure that you use the appropriate boost::python::handle<> function for your case.
If you need don't need to return a cv::Mat but different data you might consider to use boost::python::list or boost::python::dict. For example if you want to return a vectors of 2D points to Python you can do something like:
boost::python::dict toPython( std::vector<cv::Point> newPoints, std::vector<cv::Point> oldPoints )
{
boost::python::dict pointsDict;
boost::python::list oldPointsList;
boost::python::list newPointsList;
for( size_t ii = 0; ii < oldPoints.size( ); ++ii )
{
oldPointsList.append( boost::python::make_tuple( oldPoints[ii].x, oldPoints[ii].y ) );
}
for( size_t ii = 0; ii < newPoints.size( ); ++ii )
{
newPointsList.append( boost::python::make_tuple( newPoints[ii].x, newPoints[ii].y ) );
}
pointsDict["oldPoints"] = oldPointsList;
pointsDict["newPoints"] = newPointsList;
return pointsDict
}
Finally the Boost Python wrapper:
BOOST_PYTHON_MODULE( myWrapper )
{
// necessary only if array (cv::Mat) is returned
import_array();
boost::python::converter::registry::insert( &extract_pyarray, type_id<PyArrayObject>());
def toPython("toPython", &toPython);
}
I haven't tested this specific solution but it should work in principle.
This might be a little too late, but take a look at https://github.com/spillai/numpy-opencv-converter
I just downloaded Cinder v0.8.4 on my Macbook Pro running OSX 10.6.8, and started working through Chapter 1 of Welcome to Cinder using Xcode. I used the Tinderbox tool to make a new project called CinderProjectApp with default options. I also followed the instructions to ensure that my boost library is the same as the default (1.4.2).
As I began working through the tutorial, I wanted to see if I could load my own image from the /resources folder, so I downloaded an image "Broccoli.jpg" and added it to my CinderProjectApp/resources/ directory.
Here is my draw() function:
void CinderProjectApp::draw()
{
gl::clear( Color( 0, 0, 0 ), true );
try
{
std::string p = FilePath( "", ImageIo::getLoadExtensions() );
if( ! p.empty() )
{ // an empty string means the user canceled
myImage = gl::Texture( loadImage( p ) );
}
}
catch( ... )
{
console() << "Unable to load the image." << std::endl;
}
gl::draw(myImage, getWindowBounds());
}
When I compile the entirety of my small CinderProjectApp.cpp code, I get error: conversion from 'boost::filesystem3::path' to non-scalar type 'std::basic_string, std::allocator >' requested on the line where I specify the path to the file. Since this appears syntactically valid, I’m wondering what’s going wrong here with getOpenFilePath.
If you need to see the rest of the code, please let me know. By the way, I crossposted my question here.
Thanks to Paul and Sansumbrella’s help at forum.libcinder.org, I’ve moved my try-catch to the setup function (for efficiency), and used the ci::fs::path object to hold the path. Here is my new setup() function (assume that everything in draw() from above is unchanged besides the reordering of the try-catch logic):
void CinderProjectApp::setup()
{
try
{
ci::fs::path p = getOpenFilePath( "", ImageIo::getLoadExtensions());
if( ! p.empty() )
{ // an empty string means the user canceled
myImage = gl::Texture( loadImage( p ) );
}
}
catch( ... )
{
console() << "Unable to load the image." << std::endl;
}
}
Cocos2d-x is a C++ port of Cocos2d-for-iPhone. It has the advantage of cross-platform. I'm using Cocos2d-x to develop games for Android and iPhone.
Right now I'm compiling a set of Cocos2d-X code with both Android NDK and Xcode.
On Xcode the game compiles and runs well on the iPhone.
With Android NDK, the compile would fail. (I'm using the official Android r7c NDK).
Please help.
Edited: For those of you who're interested in the full implementation file. Here it is.
#include "GameOverScene.h"
#include "HelloWorldScene.h"
using namespace cocos2d;
bool GameOverScene::init() {
if (CCScene::init()) {
this->_layer = GameOverLayer::node();
this->_layer->retain();
this->addChild(_layer);
return true;
} else {
return false;
}
}
GameOverScene::~GameOverScene () {
if (_layer) {
_layer->release();
_layer = NULL;
}
}
bool GameOverLayer::init () {
if (CCLayerColor::initWithColor(ccc4f(255, 255, 255, 255))) {
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
this->_label = CCLabelTTF::labelWithString("", "Artial", 32);
_label->retain();
_label->setColor(ccc3(0, 0, 0));
_label->setPosition(ccp(winSize.width/2, winSize.height/2));
this->addChild(_label);
this->runAction(CCSequence::actions(CCDelayTime::actionWithDuration(3), CCCallFunc::actionWithTarget(this, callfunc_selector(GameOverLayer::gameOverDone)), NULL));
return true;
} else {
return false;
}
}
void GameOverLayer::gameOverDone() {
CCDirector::sharedDirector()->replaceScene(HelloWorld::scene());
}
GameOverLayer::~GameOverLayer() {
if (_label) {
_label->release();
_label = NULL;
}
}
And the full header file
#ifndef S6_GameOverScene_h
#define S6_GameOverScene_h
#include "cocos2d.h"
class GameOverLayer : public cocos2d::CCLayerColor {
public:
GameOverLayer():_label(NULL) {};
virtual ~GameOverLayer();
bool init();
LAYER_NODE_FUNC(GameOverLayer);
void gameOverDone();
CC_SYNTHESIZE_READONLY(cocos2d::CCLabelTTF*, _label, Label);
};
class GameOverScene : public cocos2d::CCScene {
public:
GameOverScene():_layer(NULL) {};
~GameOverScene();
bool init();
//SCENE_NODE_FUNC(GameOverScene);
static GameOverScene* node()
{
GameOverScene *pRet = new GameOverScene();
//Error: undefined reference to `GameOverScene::init()'
if (pRet && pRet->init())
{
pRet->autorelease();
return pRet;
}
else
{
//Error: undefined reference to `vtable for GameOverScene'
delete pRet;
pRet = NULL;
return NULL;
}
};
CC_SYNTHESIZE_READONLY(GameOverLayer*, _layer, Layer);
};
#endif
It might be problem with Android.mk file.. In that you need to add your GameOverScene.h file for compilation..
/Users/my_account_name/Desktop/Projects/S6/S6/android/jni/../../Classes/GameOverScene.h:40: undefined reference to GameOverScene::init()'
You have to link with GameOverScene's object file.
You might forget to add GameOverScene.cpp in Android.mk located at Classed folder.