Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 28 May 2011
Offline Last Active Today, 02:12 PM

#5268915 Fun Challenge: Implement Polymorphic Callback

Posted by Waterlimon on 02 January 2016 - 08:11 PM

You are relying on vendor specific behaviour.
Calling conventions are up to the compiler and platform. So calling the member function as a free function with an implicit this argument might fail.
But as long as it works...
It's the same trick that the FastDelegate library uses. Only it has compile switches for a dozen compilers or so.


I dont specify the calling convention (I never convert the member function pointer to something else and only call it knowing both the class type and member func ptr type)


AFAIK the only requirement is that the member function pointer is compile time constant (as its used as template argument to 'wrap' it into normal nonmember function). Shouldnt compile otherwise...


Im not sure if the above assumption is true for something like virtual methods (it COULD be?). But yeah I dont feel confident using it for anything else than regular member functions which I can assume are known at compile time (better be, for my performances sake)

#5268874 Contrevertial Simulator Idea - Feedback Needed

Posted by Waterlimon on 02 January 2016 - 02:30 PM

You could also implement it so that the player is not the leader, but the very idea itself.


So it doesnt matter if groups of people claiming to be the cult all die, as long as the idea survives (if your idea bans internet, it might make your cults more resistant to its members becoming sane, but it might not spread so well, etc)


Ofc it could be interesting if you can directly control the leaders or whatever (maybe the idea is so ingrained in them, you have direct control)

#5268726 Raytracer is not working

Posted by Waterlimon on 01 January 2016 - 01:32 PM

try adding a minus sign somewhere...?



try track some rays in debugger through sphere test to see why they dont hit, maybe you will find bug

#5268725 Fun Challenge: Implement Polymorphic Callback

Posted by Waterlimon on 01 January 2016 - 01:29 PM

I made this when I realized C++ is lacking in that department

//Supports nonmember and member functions, lambdas (captured parameters are not stored!)
		template<typename ReturnT, typename... ParamT>
		class CallbackBase
			//Member func as free function
			using MFuncT = ReturnT(*)(void*, ParamT...);
			//free function
			using FuncT = ReturnT(*)(ParamT...);
			template<typename ClassT, ReturnT(ClassT::*memberFunc)(ParamT...)>
			void connectMemberFunction(ClassT* object)
				mObject = object;
				mMemberFunction = &memberFunctionPtrAsFreeFunction < ClassT, decltype(memberFunc), memberFunc, ParamT... > ;
			template<typename LambdaT>
			//NOTE: Callback lifetime must not exceed that of lambda if variables are captured! Use connectFunction if lambda is noncapturing
			void connectLambda(LambdaT& lambda)
				mObject = &lambda;
				mMemberFunction = &memberFunctionPtrAsFreeFunction < LambdaT, decltype(&LambdaT::operator()), &LambdaT::operator(), ParamT... > ;
			void connectFunction(ReturnT(*func)(ParamT...))
				mObject = nullptr;
				mFunction = func;
			void reset()
				mObject = nullptr;
				mFunction = nullptr;
			//false for normal function, true for member function / lambda
			bool hasContext() const
				return mObject != nullptr;
			bool connected() const
				return mFunction != nullptr;
			template<typename ClassT, typename MemberFuncT, MemberFuncT memberFunc, typename... SuppliedParamT>
			static ReturnT memberFunctionPtrAsFreeFunction(void* object, SuppliedParamT... params)
				return (static_cast<ClassT*>(object)->*memberFunc)(params...);
			void* mObject = nullptr;
				MFuncT mMemberFunction;
				FuncT mFunction;

		class Callback;
		template<typename... ParamT>
		//Supports nonmember and member functions, lambdas (captured parameters are not stored!) [void return type]
		class Callback<void(ParamT...)> : public CallbackBase < void, ParamT... >
			using CallbackT = Callback<void(ParamT...)>;
			void connectToStub()
			template<typename... SuppliedParamT>
			void operator()(SuppliedParamT&&... params)
				assert(mFunction != nullptr);
				//Member function or lambda
				if (mObject != nullptr)
					(*mMemberFunction)(mObject, std::forward<SuppliedParamT>(params)...);
				//Nonmember function
			explicit operator bool() const { return connected(); }
			bool operator==(const CallbackT& other) const { return mFunction == other.mFunction && mObject == other.mObject; }
			bool operator!=(const CallbackT& other) const { return !((*this) != other); }
			static void stub(ParamT...)

		template<typename ReturnT, typename... ParamT>
		//Supports nonmember and member functions, lambdas (captured parameters are not stored!) [nonvoid return type]
		class Callback<ReturnT(ParamT...)> : public CallbackBase < ReturnT, ParamT... >
			using CallbackT = Callback<ReturnT(ParamT...)>;
			template<ReturnT defaultValue = ReturnT()>
			void connectToStub()
			template<typename... SuppliedParamT>
			ReturnT operator()(SuppliedParamT&&... params)
				assert(mFunction != nullptr);
				//Member function or lambda
				if (mObject != nullptr)
					return std::move((*mMemberFunction)(mObject, std::forward<SuppliedParamT>(params)...));
				//Nonmember function
					return std::move((*mFunction)(std::forward<SuppliedParamT>(params)...));
			explicit operator bool() const { return connected(); }
			bool operator==(const CallbackT& other) const { return mFunction == other.mFunction && mObject == other.mObject; }
			bool operator!=(const CallbackT& other) const { return !((*this) == other); }
			template<ReturnT defaultValue>
			static ReturnT stub(ParamT...)
				return defaultValue;

Its just a pointer to a function and a pointer to an object (which is null if its free function). Ive only done primitive testing on it so it might be breaking some rule somewhere, but maybe you get ideas.

#5268663 Isolating groups on a board

Posted by Waterlimon on 31 December 2015 - 07:29 PM

You will probably want to

1) find unassigned cell (linear search will work if this isnt a bottleneck - maybe do each search from where previous left off to not search same stuff every time)

2) flood fill from that cell until you find all cells in the connected group of cells (while forming the group which could be by assigning the group ID to each cell, or adding each cell to some group objects list of cells)

3) repeat

#5268385 Raytracer is not working

Posted by Waterlimon on 29 December 2015 - 03:06 PM

What kind of vectors does the raycasting function produce (just grab some random examples)?


Does it produce something close to (0,0,-1)?


Maybe the sphere intersection only works when it passes directly through (assuming the rays themselves are not complete garbage)

#5268379 Raytracer is not working

Posted by Waterlimon on 29 December 2015 - 02:51 PM

If you fire a ray directly at the sphere (0,0,-1), can you make it work then?


If not, problem is probably in sphere intersection.


Is the sphere positioned so that camera is not inside it, and its not behind camera (position should have negative z, further than radius)

#5268072 [Advice] 2D Game Engine/Framework w/ Good Networking Support

Posted by Waterlimon on 26 December 2015 - 03:26 PM

Hello GameDev.Net community! I am just an amateur developer and I've been trying to work on this crazy idea of mine for quite some time now. I'm kind of at a point where I might need some guidance from more experienced programmers. I'll try to be as short as I can, straight to the point.


What I want: I want a 2D multiplayer rpg game with support of, well, as many client as possible. I do NOT care if it is distributive-based or browser-based, no preference.


What I want engine-wise: A non-complicated framework or entire engine with built-in networking tools, primarily 2D-oriented but not limited to. Pretty much any technology language-wise, just as long it is adequate and reasonable to quickly grasp on and dive into.


What I know:

* VB & C++ with decent OOP knowledge;

* PHP (Procedural & OOP) + MySQL;

* Some Flash + AS3 skills;

* Basic JavaScript;

* Some scripting in Python & Lua. and don't mind to learn some more.

* C++ and PHP.


I do not want to write a game from scratch, i.e. 0-starting in C++ with WinSock and etc. Too much pain and I don't have much desire and time for that. I could do it completely in PHP+MySQL bundle and that would work except that it is almost 2016 and I want dynamic pages without the need to reload them.


JavaScript. I've been looking into some JavaScript and I lean more and more towards it but it is way too complicated, honestly with its Node.js and Socket.io and other stuff, I just don't think it's worth the time but I might revise this if you could persuade me. I'd like to keep JS as my last resort.


GameMaker & Construct. I also have looked into GameMaker Studio and Construct 2, and have played around a bit but quickly realized that with the provided capabilities it wouldn't be even nearly enough to fulfill my expectations. In addition, I've tried HTML5 and it is also not powerful enough.


FLASH & ActionScript 3. A very ugly and old way but hey, it works. I had a more-or-less working thing on PHP+AS3 bundle, however it was too buggy and let's face it, the community is dead. Flash is dead.


Look at what I have: Here's a quick example of what I am talking about (Login: Micard, Password: admin):


The chat should work, at least it used to, unless I did something to the DB. In the attachment is a quick GMS sketch as well but it does its job and represents what I want as well.


CONCLUSION: Please guide me to the direction that will help me achieve my goals. I do not plan to sell this game as a product or anything. I also don't have much time to work on games as I am an Aerospace Engineer but I do it as a hobby and that's why I avoid getting into something too deep like JavaScript. If you have any suggestions, literally, any - I'd very appreciate it!


Thank you!


There you go

#5267828 Best way to draw voxelized pyramid?

Posted by Waterlimon on 24 December 2015 - 02:33 PM

The primary drawback with that method, is that while the number of vertices drawn goes down, the number of fragments/pixels processed goes up (assuming you do hidden-face elimination which is the most important optimization here!)


Reducing to boxes never decreases number of fragments drawn. In practically all situations, it will drastically increase their amount.


Doing this would only make sense if doing this vertices-for-fragments trade results in net performance increase.

One possible scenario would be far-away chunks - where each voxel takes just few pixels on screen, shading is cheap because you dont even need textures or proper lighting at extreme distances, and further you dont need to be able to easily edit those chunks because theyre too far for such things to matter.


So, the disadvantages in a normal voxel grid scenario with high fragments-to-vertices ratio:

-Overall performance significantly decreases because theres vastly more fragments to shade (even with early depth eliminations and whatnot)

(the problem is hidden face elimination. Reducing to boxes is a limited form of hidden face elimination. Its better than the naive "just render many boxes" approach, but much less effective than complete per-voxel hidden surface elimination.)

-Cost of modifying object increases (need to recalculate the 'optimized' boxes)

-No flexibility with per-voxel/per-vertex changes (like how minecraft renders its lighting with some per-face shadow texture things IIRC). Also you cant make nonlinear transformations on the voxels because this will detach box faces and vertices from each other spatially (with normal voxels there are only vertex-vertex connections as you say)


The first one (that its a highly less effective form of hidden surface removal) is the most relevant here (discussing performance).


The conclusion would be that AS LONG AS you do not 'break' normal hidden surface elimination, this kind style of optimization helps (still the other disadvantages apply):

-you can apply it to the 2D surfaces surviving hidden surface elimination only, instead of 3D voxel regions (like you seem to have decided to do)

-you can apply it to 3D voxel regions, if most of the resulting box is visible (not hidden)


And if you DO decide to still use it, heres a performance tip for making it practical:


Perform hidden surface removal on the boxes! Only replace a voxel region with a box, when some faces of the box can be removed such that most of the resulting box surface is visible (not hidden).

Like you could split your pyramid such that each layer is formed by 4 thin and long boxes, with the 'inside' faces removed/hidden. That would be very close to an optimal mesh.

#5267613 Draw only portions of the circle visible to the user

Posted by Waterlimon on 23 December 2015 - 02:54 AM

If your circles dont change significantly over time, and/or if you have many circles that look the same, draw the circle to an image and blit that to the screen, which should perform significantly better (you can update the image, even every frame if theres many circles sharing the same image and thus saving calculations).

#5267552 Compiling and running on different OpenGL versions

Posted by Waterlimon on 22 December 2015 - 04:41 PM

Most of the openGL functions you use, are fetched from at runtime in the form of a function pointer (see openGL wiki on function loading).


Usually youd use a helper library like GLEW to automatically do the loading (it declares all the functions as function pointers and attempts to load them I assume).



So, presumably, if a function is not supported, the function pointer returned when trying to load a GL function at runtime will be nullptr or some other value (not sure what platforms wouldnt return nullptr) that will cause your program to crash if you try to call it...


This also means, you can always do checks at runtime to ensure you have the correct opengl version available, and even individual functions. If youre using a lower opengl version, you can try loading some functions not available in your gl version as an extension as well (like if theres something specific you need from the higher version, but you cant ask for full support of that version for some reason)

#5266745 Vertex hashing

Posted by Waterlimon on 17 December 2015 - 12:04 AM

It seems to work fine for me when I pass in a pointer to an array of 3 floats.


It doesnt work if I make the function take an array (it just produces undeterministic garbage), but I dont at the moment see why (Is it taking the address of a pointer? Never really use arrays this way ph34r.png )


edit: yup, the "&" needs to go...

#5265789 MSAA help

Posted by Waterlimon on 10 December 2015 - 04:59 PM

Maybe you still need to do the second step (call glEnable( GL_MULTISAMPLE )), other than that, idk

#5265767 MSAA help

Posted by Waterlimon on 10 December 2015 - 02:45 PM

I think, for the default framebuffer, you tell the windowing system to give you MSAA, when you create the context.


Section 3.2 seems relevant for that purpose in the linked page (assuming you use raw windows API and not some library for creating window/context).

#5264752 Culling? Duplicate Impulses during Collision Resolution.

Posted by Waterlimon on 03 December 2015 - 11:10 AM

Once the first collision is processed, the box is now moving away from both A/B so the second collision would automatically be ignored.


Not sure how rotation would affect it...


'Proper' physics engines probably collect all contact points and only then solve for it.



No idea really I probably shouldnt have even posted ph34r.png