Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 28 May 2011
Offline Last Active Oct 11 2016 01:30 PM

#5281052 no good way to prevent these errors?

Posted by on 13 March 2016 - 11:23 AM

If the x,z things are (mathematical) vectors, I use a vector object instead of independent variables, so I would either do

A.something = B.something

A.mSomething = B.mSomething




for(int i=0;i<2;++i)


A[i] = B[i];



Both of which reduce chance for manual errors when doing repetitive stuff.


I guess if you have an y component and want to skip that, and its a common thing, you can write a special function for that:



So whenever I do anything related to vectors/matrices I use loops instead of manually handling every component. It also usually generalizes to any number of dimensions if I care about that.



For other things, if you cant make the type checker detect the errors, see if you can change your naming conventions to highlight them better. mX instead of mx might be more visible. Also consider adding comments that state what must be done, before actually writing the code. That will force you to think a bit more and also remind if you forget something while writing it out.


In the case of using current_location instead of new_location, perhaps you can limit the scope of variables even more (such as by using anonymous scope), so theres less potential wrong choices to make. Some people might also make variables useless by setting some garbage value just after the last use (like setting pointers to nullptr after delete).


Then theres tools like assertions and unit tests, which are also a bit like comments, except theyre actually checked. People really care about writing safe and correct code, you could even look into fields where its extra-critical and see what they do.

#5280061 is there an easier way to do this?

Posted by on 07 March 2016 - 02:28 PM

For the basic information that every object needs filled in, you could write a simple editor (if theres a ton of items) that asks the data in efficient way and writes it to all the places necessary.


Ensure the common case has a sensible default that allows you to skip providing the data (probably applies to everything there). Make it so, that when adding some entirely new functionality, you can skip all the common data (appearance, physical properties...) and focus on the functionality. So you dont need to finish/decide every aspect of the entire item before it even exists. That should make it less annoying to add new things. Fill in the details later.


See if theres any way you can add more templates/helpers to minimize amount of data/boilerplate you need to input. Try to bring all the information in a single place, in correct order (having to jump around multiple places adding stuff is slow). (this is what an editor would do - even if all the data was in code, you could have some text console editor insert the data and write the boilerplate for you)

#5277803 Manufacturing chain for paper

Posted by on 23 February 2016 - 05:12 PM

Toilet paper?

#5277008 New Studio Name, Thoughts?

Posted by on 19 February 2016 - 12:56 PM



Good Bishop Studios


Bad Bishop Studios


King's Bishop Studios


Queen's Bishop Studios


Indian Bishop Studios


Bishop Pair Studios







I demand 75% revenue share

#5276017 Victory conditions for a 4X

Posted by on 16 February 2016 - 03:28 PM

It might feel better if you have to complete those achievements within limited time (it can be a long time, but still a clear limit)


Perhaps, you also need to survive until that limit, even after completing the necessary achievements.


So you have to do some time management as well. Maybe you can get all the achievements by going all in, but expend too much resources doing it and fall before the time limit. Or maybe you want to play it safe and leave a difficult achievement toward the end (eg build something big which requires selling most of your army), but something unexpected slows you down and you lose.

#5270205 none issue when near plane = 0.01, is it just matter of time when I see artif...

Posted by on 08 January 2016 - 09:19 PM

The value of near plane is irrelevant on its own - what matters is the relative magnitude of the near and far plane to each other.


Set far plane as low as you can without issues. Then near plane as high as you can without issues.


If theres no issues, everything is fine.


If there still is issues, you need to do something else in addition to simple depth testing to deal with the cases where it isnt working (like doing multiple passes for different depth ranges to increase precision withing each range, or depth biasing like you have).

#5268915 Fun Challenge: Implement Polymorphic Callback

Posted by 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 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 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 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 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 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 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 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 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.