Jump to content

  • Log In with Google      Sign In   
  • Create Account


Nercury

Member Since 19 Feb 2013
Offline Last Active Jul 21 2013 08:48 AM

#5043298 Am I a bad programmer?

Posted by Nercury on 15 March 2013 - 02:39 AM

Should we call that user a bad critic?

 

It is unhealthy an unnecessary to resort to personal judgments of author when critiquing his work.

Fine: "code has A and B problems".

Unnecessary: "therefore author is a bad coder".




#5043197 Trigonometry

Posted by Nercury on 14 March 2013 - 05:15 PM

Looks like pymunk tutorial is here:

 

https://code.google.com/p/pymunk/wiki/SlideAndPinJointsExample

 

However looks like pymunk uses compiled C lib, my knowledge ends here.




#5043014 Trigonometry

Posted by Nercury on 14 March 2013 - 05:29 AM

I can't waste the opportunity to say that many of these things are better implemented using vector algebra than angles. Angles are very intuitive, but code that uses them is often full of special cases that have to be dealt with using `if' statements, and they require using expensive calls to trigonometric functions.

 

I can't agree more: you may not know, but there is a little need of "school trigonometry" even in 3D, because everything can be done very elegantly using vectors. And all of it works on 2D, you just don't use Z axis.

 

If you store the locations for object a and b as vectors, you can:

- Get a distance between them by subtracting them and returning distance vector's length: (A-B).length() or (B-A).length()

- Get a direction A must go to to eventually get to B: (B-A).normalize() ("normalizing" always returns vector of length 1)

- Angle between two normalized vectors C and D is acos(C dot D).

 

And there are math libraries which already have all these operations written for vectors.

So if you need a rotation vector for your object to face your mouse, you would write something like this (assuming object position is in same space as mouse position):

 

#mousePos = ...
#objectPos = ...
initialLookDirection = Vector2(0, 1) # intitally your object looks "up", if Y axis is "up"
targetLookDirection = (mousePos - objectPos).normalize()
rotationInRadians = acos(initialLookDirection * targetLookDirection) # "*" is "dot" product in pygame Vector2

 

For pygame, you would use pygame.math.Vector2.




#5042435 Starting Game Engine

Posted by Nercury on 12 March 2013 - 02:33 PM

The best way to learn how to make game engine is to make a game. Now I need to apply this wisdom to myself smile.png

 

Don't get me wrong, I want to learn how to do it. I've just no clue where to take the next step after all c++ basics.

 

My lecturer a few years ago gave me a few tasks:

 

Basics:

- Render a triangle, triangle with texture, make triangle spin.

- Bonus points: do it with shaders too.

 

Matrices and delta time:

- Make an Earth model that has a Moon and turns around the Sun. This small solar system model should have correct rotation based on the real world data. You should be able to speed-up/slow-down the time. Models can be simple wireframe or solid color.

- Bonus: texture them, add correct light.

 

3D basics:

- Render a globe (or any curved model) with a texture correctly applied. Then make it smooth by using the correct normals.

- Render a model loaded from a file. File format is not important. Animate it: make it move/spin.

- Make a few kind of lights: a spotlight, point light, sun light.

- Make an object cast a shadow.

- Implement basic collision for something.

- Make a camera, which is switchable between three modes: FP walk, FP fly, examine (you turn around the target, or third person).

- Bonus points if you do it with shaders.

- Bonus points: make the same object cast shadows for all light types.

- Bonus points: make the shadow nicely blur and fade out in a distance.

 

By the time you finish this, you will have a much better understanding of many things, which will help you in many aspects of games programming. You can even do these things as part of some small game(s), to make it less boring. All of this can be done with the tools of your choice.




#5042344 Game-making platform for everyone

Posted by Nercury on 12 March 2013 - 09:22 AM

$19 per month for the monthly subscription of using "The Editor".

 

or

 

Create my own editor for your "open source front end".

 

No, thank you. That's what I think smile.png.

Further comment: It seems to be more targeted to designers, not programmers. It looks kind of limited to me, because the game can only support only the things "editor" and "realm" does support. Getting into it and hacking additional stuff requires a lot of knowledge, plus getting familiar with your API.




#5042307 [HTML5] I suck at it please help with short code

Posted by Nercury on 12 March 2013 - 08:00 AM

Analogical code implemented using jquery would look like this:
 
<!DOCTYPE html>

<html>
<head>
   <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head>
<body>
    
<script>
$(document).ready(function() { // this makes it execute only when DOM is loaded
    $("#ho").click(function() { // run this when element with id "ho" is clicked
        var $h = $("#hi"); // find element with id "hi"
        alert("I love " + $h.val());
    });
});
</script>

<form>
    <input type="text" id="hi">
    <input type="button" id="ho">
</form>

</body>
</html>
I am posting this as an example. Obviously, jQuery library takes some time to load, but it already solves many DOM manipulation tasks, and hides browser differences. The main advantage of jQuery is that your javascript is completely separate from HTML code.


#5041349 Creating a "Music Video Game"?

Posted by Nercury on 09 March 2013 - 07:50 PM

I was working on something similar to this, it was an attempt to manipulate audio based on input from a webcam or camera.

 

We used C++, SDL, OpenCV and SDL_sound.

Interestingly, capturing video frames with OpenCV and even basic analysis of video (like brightness) was quite easy to do. The tricky part was reliably layering many audio tracks without any delays or glitches. SDL_mixer was completely unreliable and caused delays because of it's internal threading. SDL_sound required more work and we have not managed to make it glitch-free before our interests faded :)

If I ever do this again, I would try another, maybe more reliable audio library like OpenAL. However my experience ends here.

 

Based on your question, my suggestion would be to have a better idea of how your game (or interactive experience) should work. Maybe you won't need to write it from scratch like we tried to do :)




#5041339 openGL app not working outside of visual studio.

Posted by Nercury on 09 March 2013 - 07:15 PM

It could really be anything.

It can be

 

Thing *t = new Thing();
delete t;
delete t; // cleaning same memory twice

 

Or

char *c = new char[10];
c[10] = 10; // array writing out of bounds, you can overwrite some other heap object without even a warning!
// I think this is worst kind of thing, because your error will happen somewhere else, and will be unpredictable

 

Or

Thing * returnIt() {
    Thing t;
    return &t; // if you return pointer to local variable it no loger points to valid memory
}

Thing *t = returnIt();
t->use(); // crash

 

Many things. Actually here is a list from stack overflow:

 

 

Common scenarios include:

  • Writing outside the allocated space of an array (char *stuff = new char[10]; stuff[10] = 3;)
  • Casting to the wrong type
  • Uninitialized pointers
  • Typo error for -> and .
  • Typo error when using * and & (or multiple of either)
  • Mixing new [] and new with delete [] and delete
  • Missing or incorrect copy-constructors
  • Pointer pointing to garbage
  • Calling delete multiple times on the same data
  • Polymorphic baseclasses without virtual destructors



#5041336 When to start with C++?

Posted by Nercury on 09 March 2013 - 07:04 PM

Just some anecdotes from me too:

 

I knew some languages when I started, Java/Delphi/VisualBasic. So I could do basic programming without thinking too much about it.

 

First time I started with C++ when I had to do some university assignments with it. I remember passing *** pointers to pointers between stuff and learning never to clean up memory because that got in a way of finishing my task... Loads of trouble. I also learned that you can get ridiculous stuff to compile with C :). And even work somewhat, and print endless strings of OS memory. Fun.

 

I tried to stay away from C++ since then, got into C#.

I remember making DirectSound filter with C# and realized that you can't compete with compilers like C in areas such as real-time sound processing. Just no easy way.

Later I got into XNA right when it appeared. I experimented with HDR post-processing effect in XNA and also got a bit disappointed in speed limits. You just can't beat no-check, direct memory access.

 

Later I worked on some networked application and I did it with C++. That's when I learned real C++: standard library, threading (with boost), templating, and wrote my own smart pointer template (although later I realized it already existed). The bugs I made were very tough. They really bite you in C++, especially pointer-related things.

 

So to answer your question. When will you know to move to C++? I know that if i had moved to it sooner, I would had learned it sooner. It is simple as that :).




#5040981 Little help needed

Posted by Nercury on 08 March 2013 - 04:38 PM

Singleton suggestion (single, global class) is most likely a correct answer to your question.

 

However, I wonder what your input class actually do. Maybe this particular case can be elegantly solved without a global variable.




#5038583 Engine object creation strategy.

Posted by Nercury on 02 March 2013 - 06:49 PM

I would avoid hiding things. If you think FontManager is too complex to assign to your control, maybe control does not need to get full access to it.

 

For example, I have similar system, and I require to pass Font when creating my Control, and Font needs my FontManager to create :). And it looks nice:

 

Font * smallFont = new Font("FreeMonoBold.ttf", 10, fontManager);
TextLine t(smallFont);

 

 

Of course I am lying, it does not look like this, it is crappier and I wrap my heap objects in shared_ptr.

But maybe it will give you some ideas :)




#5038398 function calling out to others? (c++)

Posted by Nercury on 02 March 2013 - 06:13 AM

You can do it Java way.
Create DateDispatcher with methods:

  • changeDate(newDate)
  • addListener(listener)

Make another base class for date change listener, BaseDateChangeListener, with virtual methods:

  • virtual onMonthChange(newDate)
  • virtual onYearChange(newDate)

Make DateDisplatcher contain list of listeners and inform them about month and year change when needed.

You can use this DateDispatcher in many projects, it does not depend on specific project stuff.

Then you can make project specific class that "does stuff", named ClassThatDoesStuff that derives from BaseDateChangeListener.

 

class ClassThatDoesStuff : public BaseDateChangeListener {
public:
    virtual void onMonthChange(date newDate) {
       // do project-specific stuff
    }
    virtual void onYearChange(date newDate) {
       // do project-specific stuff
    }
}

 

And add it as listener in DateDispatcher. This way you can keep your project logic separated from this small tool logic.

Edit: for date and time manipulation you can use boost::date_time.




#5037933 Network Interpolation Help

Posted by Nercury on 01 March 2013 - 01:42 AM

I recommend this read (although there are a lot of Unreal specific things, many things can be simplified):

http://udn.epicgames.com/Three/NetworkingOverview.html

To summarize:

A client does not know about objects until server decides they are relevant to him. Server keeps track of what objects are replicated to client and periodically sends state updates.

You run the same simulation on both client and server, with the exception of server-specific and client-specific things.
For example, server will need to send updates to other clients, client may want to read user input or animate additional eye candy which is not needed on server.

 

Additional tracked data usually include velocity vectors. For example, if object is moving to X direction, client continues simulating it's movement even if no updates come from the server. Of course, this leads to small inaccuracies, and updates from server usually snaps it back to "reality".

For this to work, you also need to keep track of network latency.

You will know that, for example object P was at position (x, y) with movement direction to (i, j) at speed s, and it happened t time ago. Based on this data, it is easy to calculate it's position on the client.




#5037736 having multiple monsters in one text file

Posted by Nercury on 28 February 2013 - 02:44 PM

You can store these things in json file ("example.json"):

 

{
	"monsters": [
		{
			"name": "Rabbit",
			"hp": 30,
			"attack": 5
		},
		{
			"name": "Rat",
			"hp": 40,
			"attack": 10
		}
	]
}

 

And load using python JSON library (included in Python 2.6):

 

import json

config_file = open('example.json')
data = json.load(config_file)
config_file.close()

for monster in data["monsters"]:
    print monster



#5037677 simple structs initialization optimization

Posted by Nercury on 28 February 2013 - 11:57 AM

In short, I think my question really is: Is C#'s "var myVec = new Vector(0f, 0f, 0f);" as fast as C++'s "Vector3 myVec( 0.f, 0.f, 0.f );" ?

 
As per lwm's answer IL looks like it should be so. My gut feeling tells me that it will be quite hard to even measure the difference (all the variables land on stack and method most likely is inlined). And the real answer, as always, is in actually measuring it smile.png




PARTNERS