Jump to content

  • Log In with Google      Sign In   
  • Create Account

Misery

Member Since 27 Sep 2010
Offline Last Active Aug 13 2014 06:41 AM

#5166807 What is low-poly (nowdays)

Posted by Misery on 14 July 2014 - 02:38 PM

Thanks a lot guys! :]




#5166455 Open world game design in Unity

Posted by Misery on 12 July 2014 - 02:10 PM

@GoCatGo thank you very much. That was actually an answer that cleared everything to me at the moment. As you suggested I will start with "smaller" approach.




#5015404 Program Wide Global Vars in C++?

Posted by Misery on 29 December 2012 - 05:58 AM

It may be breaking the laws of OOP but I was just wondering if it was possible in C++.

 

I don't feel like it is breaking the laws of OOP. It depends on what you need. Sometimes it is used as it is the most convienient approach. Please see info about singleton pattern. It is considered an alternative to global variables.




#4963893 Overload comma , operator to init the array

Posted by Misery on 28 July 2012 - 03:01 AM

@Aardvajik:
Hello,
I am a scientist in CFD. I was asked to create a "friendly" library for scientific computations. I know, there are many of those, but none of them fulfills all of these criteria at once:
- includes matrix classes, sparse matrix classes, graphs, FEM meshes, solvers (I know, I know, Dune does for example) under one common interface
- is intuitive for people using Scilab, Matlab, Octave, Mathematica etc (this is why I aim to create such syntax)
- has easy to use installer on both Windows and Linux
- is portable between Windows/Linux and Intel C++, VS C++ and GCC on those platforms
- is written in compiled language, so it is much faster than scientific script languages, and avoids copying of arrays (what is common in Scilab for example)
- to use: include only one header and done, no needed fortran to C and C to C++ etc compilations, using Linux to windows cross compilers and so on

And to give You straight answer: Engineers and scientists very often use Mathematica, Matlab and silimar things.
And quite often we begin to learn programming using these (btw great) packages. And these script languages are oriented for using matrices, the same way as it is in engineering practice. We are used to init matrices "by hand". However, as one develops oneself tries to count more and more complicated things. And at some moment those scientific packages seem too slow, even to use them at super computers (on our HPC Task server, if Your computations are not finished in a week, they are canceled).

So what I am trying to do is to create intuitive library, which can be easily installed and used by non-proffesional programmers (like myself).So they could easily count much larger cases than before.

I am guessing that You are a pro programmer. So Your viewpoint to this matter is quite different than someones who is just trying to do different job, but needs to create program to count anything. For You it is not a problem to choose a language, dependently to what You need to achieve. You need a good parsing - take Python, You need fast numerical algorithms - take C++ or Fortran. Need administrative scripts: take PowerShell or Perl...
But we - non-profesionals - don't look at those matters this way. Our job demands from us bit different things, and we are not (unfortunately) paid for spending time on learing new programming language.

You would be surprised how little most just-programming-users enigneers know about programming. Posted Image


#4963883 Overload comma , operator to init the array

Posted by Misery on 28 July 2012 - 02:01 AM

Thanks to (Servant of the Lord)'s idea I've managed to do a syntax that works exactly as I wanted, and - at least to me (but I'm not an experienced programmer) - seems quite effective. To get even nicer, this solution cannot be used in VC++ but, it doesn't collide with it (maybe someday they will support init lists, as they have appropriate headers and stuff). So this initializer constructor can be defined, but cannot be used in VC++, but works with compiers that support this feature. I have tested it in Ubuntu Linux 12.04 with its default GCC compiler suite. I'm just putting it here if someone would search for such snippet.

Thanks Gyus for Your time! And special thanks for suggestions not to overload comma operator. :]

The row class:
template<class DATA_TYPE,class INT_TYPE>
class Row
{
  public:
	Row()
	{  }
	Row(const initializer_list<DATA_TYPE> &list) : L(list)
	{  }
	DATA_TYPE operator [](INT_TYPE i) const
	{
	   return *(L.begin()+i);
	}
	INT_TYPE Size() const
	{
	  return L.size();
	}
  private:
	const initializer_list<DATA_TYPE> &L;
};

Matrix class:
template<class DATA_TYPE,class INT_TYPE>
class Matrix
{
  public:
	 DATA_TYPE *Data;
	 INT_TYPE Rows,Cols;
	 Matrix()
	 {
	   cout<<"basic ctr"<<endl;
	   Data=NULL;
	   Rows=0;
	   Cols=0;
	 }
	 Matrix(initializer_list<DATA_TYPE> RowVec)  //initializer for M={1,2,3,...,N}
	 {
		Data=NULL;
		Rows=0;
		Cols=0;
		Cols=RowVec.size();
		if (Cols==0) Free();
		else
		{
		   Alloc(1,Cols);
		   INT_TYPE k=0;
		   typename initializer_list<DATA_TYPE >::iterator i=RowVec.begin();
			for (i=RowVec.begin();i!=RowVec.end();i++) Data[k++]=*i;
		}
	 }
	 Matrix(initializer_list<Row<DATA_TYPE,INT_TYPE> > RowsL)  //initializer for M= { {}, {}, {}}
	 {
		Data=NULL;
		Rows=0;
		Cols=0;
		Rows=RowsL.size();
		if (Rows==0) Free();
		else
		{
		   INT_TYPE k=0;
		   typename initializer_list<Row<DATA_TYPE,INT_TYPE> >::iterator i=RowsL.begin();
		   Cols=(*i).Size();
		   Alloc(Rows,Cols);
		   for (i=RowsL.begin();i!=RowsL.end();i++)
		   {
			  if (Cols!=(*i).Size()) { Free(); /* throw an error: inconsistient row/colums dimensions*/cout<<"Err: ircd"<<Cols<<endl;}
			  else
			  {
				 for (int j=0;j<(*i).Size();j++)
				 {
					 Data[j*Rows+k]=(*i)[j];
				 }
			  }
			  k++;
		   }
		}
	 }
	 void Alloc(INT_TYPE R,INT_TYPE C)
	 {
	   Free();
	   Data=new DATA_TYPE[R*C];
	   Rows=R;
	   Cols=C;
	 }
	 void Free()
	 {
		delete[] Data;
		Data=NULL;
		Rows=0;
		Cols=0;
	 }
};

And now it is possible to use initialzier lists, in similar way as it is in Mathematica. So it is possible to init any rectangular array in a nice looking and intuitive fashion, for example:
Matrix<float,int> M,E,r,c;
M={
		{0,1,0},
		{0,0,0},
	 };

E={
		{1,0,0},
		{0,1,0},
		{0,0,1}
	 };

r={3,2,1};
c={
	  {1},
	  {2},
	  {3},
	  {4}
	}

Regards Posted Image

PS.: #include <initializer_list>


#4960881 Is using std::move() necessary?

Posted by Misery on 19 July 2012 - 04:36 AM

@Zoomulator: That is the case, making the long story short, the matrix looks like this:
template <class DATA_TYPE,INT_TYPE>
class Matrix{
private:
   DATA_TYPE *Data;
   INT_TYPE Rows,Cols;
public:
  //all the stuff
};



#4960866 Is using std::move() necessary?

Posted by Misery on 19 July 2012 - 03:44 AM

Thanks a lot :]
Your answers let some light into dungeons of my programming adventure Posted Image


#4960824 Function taking as an argument std::equal_to, std::grater etc

Posted by Misery on 19 July 2012 - 01:21 AM

Thanks a lot :]
Your suggestions Gyus, did the job!


#4935553 MSVC 2010 strange behavior

Posted by Misery on 28 April 2012 - 03:57 AM

I admit, that I did not care about this warning, because I wanted to use technique described in C++ for game programmers. There is a statment, that says, it should automatically create a copy of an object but there it didn't point to really temporary object. I misunderstood the example i guess. Anyways, I've learned something new and that is important :]


#4905351 Pointer to function returning void

Posted by Misery on 23 January 2012 - 12:34 AM

thanks,
I see the mistake: brackets were placed incorectly :-p


#4898094 Cross platform GUI toolkit

Posted by Misery on 30 December 2011 - 04:05 AM

If You care about python embedding and GUI, why not to try to create the whole app in Python, and just make the speed critical parts in C++? There are many GUI tools for python, also "built in" in standard python modules, so maybe it is a way to achieve Your goal? And Python is cross-platform by definition, so it could solve a lot of problems at the very beginnig.


#4897635 Function that returns a function pointer

Posted by Misery on 28 December 2011 - 04:41 PM

If it is C++ maybe it is worth trying to use functor instead of function pointers.
class Stupid
{
public:
  void (*GetFnValue( char* key ))( );
};

The above code could be changed to:
class Stupid
{
public:
  MyFunctorClass FunRetFun(argtypes arguments)
};

and the latter part:
class MyFunctor{
   public:
   MyFunctor(char* key)
   {
	 //do some stuff
   }
}


and if You want a function returning a function it would just be sth like this:
MyFunctorClass Stupid::FunRetFun(argtypes arguments)
{
  //do something
return SomeInstance of MyFunctorClass;
}

I don't know if thats handy in Your application, but in a few programs that I have created it worked very well and it was much more comfy to use.
Regards


#4834903 CUDA hello world MSVC

Posted by Misery on 13 July 2011 - 11:00 AM


I don't give up easily

You copied 5 lines of code, then gave up.

"Easily" would actually mean putting in effort.

And sometimes it is better to leave something at the beginning than waste a few months for learning how

You typed 5 lines of code.

And months? I've been learning for a decade now and slowly a few small pieces are starting to make sense.


This is why consultants charge so much. Because their fee is a fraction of the cost needed to actually learn something.

Well I'm a scientist in fluid mechanics


Let me guess. This programming stuff is beneath you and so trivial it's not worth spending your mental effort on.


LMAO
You seem very frustrated.
Some things are just not worth effort, that's all.
Don't take it personally. You know nothing about my work, and what I do. You are probably paid for programming
and I am not. I'm not educated programmer and often I need help, that's why i post at this forum. I wonder how
smart would you be if you had to learn tensor analyses and fluid mechanics yourself...
so don't fuss too much.

And if after 10 years of doing exactly one thing, you still are not (as you say) good in it...
well... I think you have made a wrong choice choosing this kind of work.


#4830576 how to malloc memory properly?

Posted by Misery on 03 July 2011 - 04:44 AM

You're posting about problems stemming from errors caused by non-constructed non-pod types (a very dangerous thing to do), but are going to criticize the standard library for having strange resizable-bool-array iterator semantics?

Are you making a resizable array of bools or a resizable array of non-pod types?


vector <bool> has not only strange non-stl semantics. It also forces compiler to optimise code inproperly. If many clever ppl say: never use vector<bool> i do not use it.
And the other thing is that vectors are quite big 20 bytes for an empty vector. One more thing is that vectors reserve much more memory than needed. I know that one can use v.reserve()
but after I exceed reserved memory it will reserve again twice more than needed and so on.
In fact I need a bit array. My basic class is byte that allows me to access every bit.


#4830366 how to malloc memory properly?

Posted by Misery on 02 July 2011 - 09:30 AM

Why not stl?
Does something like vector<bool> tell You guys something?:cool:
Thats why not stl.




PARTNERS