Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 20 Aug 2009
Offline Last Active Mar 23 2014 07:00 AM

#5131585 Std vector, sorting and/or filling

Posted by TheUnnamable on 15 February 2014 - 12:32 PM

Are you sure you certainly need a vector?

If your elements are unique, you could use an std::set or std::map, which both offer sorting, you'd only have to roll your own compare-function.

#5129049 will mingw optymize ...

Posted by TheUnnamable on 05 February 2014 - 10:20 AM

passing with & * is dirtier to read test etc
I don't see how using references would be dirtier.
struct float3 { float x,y,z; };
float3 cross(const float3& a, const float3& b)
   float3 out;
   out.x = a.y * b.z - a.z * b.y;
   out.y = a.z * b.x - a.x * b.z;
   out.z = a.x * b.y - a.y * b.x;
   return out;

This will eliminate two ( unnecessary ) copies, and the function definition also tells you that the two input parameters are read-only, so you can depend on their values staying the same after the function call. Notice how the function body didn't change at all. You'd use the function the same way you did before, too.

#5124006 I'm having doubt about my map loading method and its performance.

Posted by TheUnnamable on 15 January 2014 - 05:13 PM

For starters, switch from text to binary :) It will be much faster, since you don't have to go through hundreds of characters, you just read a piece of data and there you are.

I remember seeing people just directly reading into the variables ( ie. foo.read(&mapWidth, sizeof(int)); ) and writing them as they are. This is certainly fast, but I'm not sure if this is good practice - issues could emerge when you copy a map from your computer to another and they happen to use different endianness. Still, I don't know how relevant this problem is, I hope somebody more experienced will answer :)

If it is of concern, you could use some fixed endianness in your files, and swap your byte order if while reading/writing if the running machine uses a different one.


In case it's of any help, I've written a simple library which does what I've described in my previous sentence. At start it checks what endianness the machine uses. Then you can create buffers, fill them with ( endian-correct ) data and flush those buffers to some file stream or whereever you wish. At reading you can load the whole file into a buffer and read from it, endianness will be handled. Although you have to tell each buffer what endianness they should use. ( i.e. if the buffer's endianness differs from the system's, it will flip the byte order ). Feel free to use it or just check the code :)

#5123194 Programming experiments/surveys (games)?

Posted by TheUnnamable on 12 January 2014 - 09:32 PM

I'd second HTML, it has a really simple syntax, easy to learn. You can make it interactive with JavaScript. With some programming knowledge ( judging by your post, I think you have it ) it's not hard to learn its syntax. jQuery ditto.
Still, I'd like to add that to store any kind of data, at least you would need PHP*. You can get away with simply learning a few file functions ( fopen, fwrite, fread, fclose, maybe flock ) and basic syntax ( you don't declare variables just use them, and they start with $, eg. $foo=2;). To be able to run PHP, you need hosting. Lots of free hosts are available.

To show videos you'd get a free flash solution ( flowplayer? didn't do this kind of stuff in a while ), which is basically copying a few files over and pasting a piece of code. Flashing images for really short whiles can be done with JavaScript.


* - Well, technically you can indeed get away with pure HTML+JS by setting up a node.js server. But I don't think you'd want to do that as a beginner tongue.png

#5120252 Math?

Posted by TheUnnamable on 31 December 2013 - 02:12 AM

Apart from that, a useful skill is being able to create formulas for various stuff. I use it to determine how does a light fade with distance, but the same thing can be used to determine splash damage, or you can create a formula to determine how much XP does each character level need to proceed, how much gold do you get given the monster's strength, etc. etc. If you can visualise a few formulas, it'll be fine ( power(x,n) - particularly square root and square, sin, cos, 1/x, I think you will be mostly fine with these ).


Also, linear interpolation, aka. lerp. Nothing fancy ( y=a+(b-a)*x ), but it can be incredibly useful if you know what it does. You can even play around with x and apply additional functions to it. For example, if you want to make it interpolate more smoothly, you can use (1-cos(x*pi))/2, if you want to make it interpolate "suddenly", you can use x^n. Some more complicated methods exist for interpolation, but I personally haven't used them that much.


Edit: The most basic vector math you might want to know is get a vector's length ( sqrt(v1^2 + v2^2 + ... + vn^n), where v's are the vector's coords ), direction ( see atan2 ), pitch ( atan2, but instead of atan2(y,x), you use atan2(z, veclen(x,y)), where z is up/down and y is front/back ), and do all of these backwards: to create a vector from direction, pitch and length:

//dir and pitch must be in radians ( 1 deg = pi/180 rad )
//If you are working in 2D, you might want to negate y to make y+ point downwards on the screen

To normalize a vector, you divide all of its components by it its length, and now you can easily represent a direction with it. You can for example add them up and normalize the result to get an average of the directions ( which could be more straightforward than using angles and mapping them, checking for overflows, etc. although I believe this is debatable ). Or you can check if one direction looks away from the other by taking their dot product and checking if it's negative ( when using normalized vectors, their dot product is the cosine of the angle between them ).

A lot of these tricks can be found with a proper understanding of the topics posted above.

#5118544 Setting up GLFW3 in Code::Blocks (windows)?

Posted by TheUnnamable on 21 December 2013 - 05:39 AM

I hope this helps, even though I'm using 32bit builds.


These are my linker settings for glfw projects. In case this didn't help, could you give a few "undefined reference to..." messages? Knowing what kind of functions it misses might help.

#5113750 newbie, blender and 'raw faces' models

Posted by TheUnnamable on 02 December 2013 - 08:23 AM

Also, you can convert it to triangles/quads only. Select the mesh (rightclick), enter edit mode (press tab), select all ( press A 'till the whole mesh is orange ), then press Ctrl+T to convert to triangles, or press Alt+J to convert to quads ( doesn't always work, e.g. if you have some faces wrong ).

Press tab again ( back from edit mode to object mode ), then export.


As a sidenote, did you consider OBJ's?

#5110729 display html

Posted by TheUnnamable on 20 November 2013 - 04:11 AM

Or it's BSD-licensed counterpart: http://berkelium.org/

( At least, it's worth knowing about )

#5105248 Techno-Babble screens

Posted by TheUnnamable on 28 October 2013 - 07:43 PM

If you *really* don't want to put too much CPU into these screens, you can always just pre-render your stuff offline.

E.g. you can render lots of source code into a small texture ( e.g. using a 3x4 sized font, you can fit 256x256 characters into an 1024x1024 texture ), and the same with hexdumps. You can write a smaller piece of code rendering some randomgenerated mesh and highlighting some vertices on it, adding a few bits of random text at the left side ( just make the line-lengths feel natural, it looks weird when there's too much difference in linelengths ), make your animation loopable and then pre-render it into images. I'd suggest low framerates.

Voi'la, you now have lots of screens rendering simple textures. Heavier on memory, lighter on CPU. Of course, you can use hybrid approaches too.

#5104583 How to check that two nodes of quadtree are neighbours?

Posted by TheUnnamable on 26 October 2013 - 09:56 AM

How about simply checking the node's edges? E.g. when checking east, you could do

(node1.x+node1width) == node2.x

And the same for other directions. It would be four checks at most.

#5097932 Gaussian blur with large radius

Posted by TheUnnamable on 30 September 2013 - 02:58 PM

You should skip 1. By simply downsampling the image and then stretching it again to screen-res ( or your original res ) adds some bluring to it, although it's not that nice. So you apply a gaussian blur to it and it gets smooth. ( Maybe you want to skip 3 too? )

Hmpf, I guess averaging is a good solution too. If you have the time, I suggest you to try a few techniques that come to your mind, so you can compare them quality- and performance-wise smile.png


Edit: Oh, sorry, didn't check the article. In case of bloom, you indeed want to do 3 too. You can do it for a simple blur too, but I think it's too costly since you could do it without looping.

#5090894 Thick Lines

Posted by TheUnnamable on 01 September 2013 - 05:29 PM

Usually this is done by drawing the expanded lines without modification and drawing circles where the lines meet.
Maybe my information is a bit outdated, but OpenGL has an extension to draw smooth points ( eg. circles ), but creating the circles in the geometry shader would be a certainly working solution. More costly, though. I would advice to change the circle's level of detail depending on the line's thickness ( thus the circle's radius, obviously ). I think using the circle's circumference to determine the circle's LOD would give nice results.

#5048368 Mesh Format Confusion

Posted by TheUnnamable on 30 March 2013 - 01:27 PM

Most of the big teams have their own formats, which are close to the processed ones. So they can just load the whole file into RAM and use it.

Probably, you'll just want to have a format which supports all the features you need. Also, I suggest looking into AssImp, if you need a library ( http://assimp.sourceforge.net/ )

#5042515 Model with texture animation and particle emitters

Posted by TheUnnamable on 12 March 2013 - 05:55 PM

These models are composed of separate nodes. Each model file contains its own meshes, skeletons, particle emitters, effects, etc. Then, it is up to the program to handle these nodes and render each of them.

#4943806 What are the benefits and disadvantages of using Game Maker for 2D game dev...

Posted by TheUnnamable on 27 May 2012 - 03:27 PM

The pros are that it's quite easy, gives you some flexibility with scripting, and you can use it for fast prototyping. Also, you can use some third-party stuff ( like DLLs, DyLibs, extensions or libs ) for more complex projects. It's also a nifty tool for targeting handheld platforms, but I have no experience with that.
Personally, I've found the lack of structs and classes limiting once, but I've found a quick and painless workaround for that. If you have a limit that doesn't lie in the scripting language, then you can just skim the forums for a DLL.
The cross-platform issue depends on your budget. You can buy it for Windows, and then pay separately for the other platforms.