Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411423 Posts in 69363 Topics- by 58416 Members - Latest Member: JamesAGreen

April 18, 2024, 05:11:12 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)General thread for quick questions
Pages: 1 ... 8 9 [10] 11 12 ... 69
Print
Author Topic: General thread for quick questions  (Read 134435 times)
ProgramGamer
Administrator
Level 10
******


aka Mireille


View Profile
« Reply #180 on: August 28, 2015, 05:37:30 PM »

Is that functions supposed to return the initial speed of a jump?
Edit: After a quick look at physics equations, your function should return the exact initial speed that you need to have. I don't get why you want more accuracy...
« Last Edit: August 28, 2015, 05:52:53 PM by ProgramGamer » Logged

InfiniteStateMachine
Level 10
*****



View Profile
« Reply #181 on: August 28, 2015, 06:01:20 PM »

Alright, so I'm going through a book right now to learn java, just to get general programming knowledge. I chose it because it is similar to C++ which I plan to learn after getting a handle on Java. I've never learned a programming language before, besides some minor scripting in GM. Do you guys think Java would be a good option for me making some simple game-like programs until I have a good enough grip on coding to move on to C++?

If you're planning to just make your own stuff, it's unlikely you'll benefit from switching to C++. It's a good idea to look around the different languages and see what you like most though. (I'm personally very happy with Rust as an ex-C/C++ and C# developer)

That's a good point. If you don't plan to work in the industry you are in a unique position to play with some awesome emerging languages.

I wish I had more time for D/Rust/Lisp.....
Logged

Afinostux
Level 2
**

Forgotten Beats


View Profile
« Reply #182 on: August 29, 2015, 12:42:12 AM »

Found the answer to my question! Accumulated rounding errors from adding gravity every frame vs. the relatively clean prediction function. Fixed it by adding a small amount of error correction based on the requested distance. The number is magic, I ended up just having to tune it until it worked.

Code:
inline
float jumpVelocityFromHeight(float pixels, float gravity)
{
   float jeq = (pixels + pixels * (0.0135)) * gravity * 2;
   return sqrt(jeq);
}

As far as what I need the precision for, this is one of a number of functions intended to make the player movement more predictable, so that I can prevent my random level generator from placing platforms that allow easy sequence breaks. If someone finds a skip, I want them to have earned it Grin

Also, it's equally important to detect when a jump is impossible due to a low ceiling, so the previous version that overshot its target could potentially have generated some unintentionally tricky jumps.

I wish I had more time for D/Rust/Lisp.....

Haven't tried the others, but I had a good chance to try Rust. Didn't much care for it. Not a fan of compilers that enforce code style.
Logged

InfiniteStateMachine
Level 10
*****



View Profile
« Reply #183 on: August 29, 2015, 05:37:03 AM »

I guess that's fair. I don't know enough about rust to comment on it.

In larger projects enforcing a particular style could be quite beneficial though.
Logged

Photon
Level 4
****


View Profile
« Reply #184 on: August 29, 2015, 01:37:09 PM »

Where is a good source of information for diving deeper into how programs manage memory? I feel like I keep trying to design efficient objects without truly knowing for sure what that entails in the first place. Specifically, I'm programming in Haxe.
Logged
Dacke
Level 10
*****



View Profile
« Reply #185 on: August 29, 2015, 01:51:44 PM »

The most common computer science advice given regarding stuff like that:
  • premature optimization is the root of all evil
  • profile/benchmark to figure out where you can make real gains, theorycrafting rarely works

Basically, it's really complex and it works differently for different platforms/hardware/languages/etc. That said, I find it interesting and fun to learn about stuff like that, though I don't have any good resource to give you beyond StackOverflow/wiki stuff. Just remember to benchmark and to prioritize code readability/maintainability unless you have a really good reason not to.
Logged

programming • free software
animal liberation • veganism
anarcho-communism • intersectionality • feminism
Photon
Level 4
****


View Profile
« Reply #186 on: August 29, 2015, 02:59:28 PM »

premature optimization is the root of all evil
I feel like I've heard that one before... My Word!

Fair enough to bring up again though. Hand Thumbs Up Left
Logged
qMopey
Level 6
*


View Profile WWW
« Reply #187 on: August 29, 2015, 05:02:51 PM »

Where is a good source of information for diving deeper into how programs manage memory? I feel like I keep trying to design efficient objects without truly knowing for sure what that entails in the first place. Specifically, I'm programming in Haxe.

Well you just want to avoid allocating and deallocating things when you can. For haxe specifically I imagine that programmers usually use haxe so that they can try to ignore memory management. Maybe you ought to try reading up on another language where the user deals with memory management explicitly.
Logged
Photon
Level 4
****


View Profile
« Reply #188 on: August 29, 2015, 05:11:22 PM »

Where is a good source of information for diving deeper into how programs manage memory? I feel like I keep trying to design efficient objects without truly knowing for sure what that entails in the first place. Specifically, I'm programming in Haxe.

Well you just want to avoid allocating and deallocating things when you can. For haxe specifically I imagine that programmers usually use haxe so that they can try to ignore memory management. Maybe you ought to try reading up on another language where the user deals with memory management explicitly.
Its not so much that I want more control over memory, I just wanted to have a better idea on which actions in Haxe did what.
Logged
Afinostux
Level 2
**

Forgotten Beats


View Profile
« Reply #189 on: August 30, 2015, 01:46:20 AM »

The first guy is pretty opinionated and ranty (I say as a C guy), but this discussion might be what you're looking for. They discuss the garbage collection in Haxe, and compare it to direct memory management in C++. Hope that helps!
http://old.haxe.org/forum/thread/3036
Logged

Layl
Level 3
***

professional jerkface


View Profile WWW
« Reply #190 on: August 30, 2015, 06:50:44 AM »

I guess that's fair. I don't know enough about rust to comment on it.

In larger projects enforcing a particular style could be quite beneficial though.

In Rust it's especially great that it's enforced across libraries, making all code look uniform. (That said, they're only warnings and you can disable them)
Logged
gimymblert
Level 10
*****


The archivest master, leader of all documents


View Profile
« Reply #191 on: September 06, 2015, 09:24:55 PM »

Hello thanks for everyone who help me on the Json problem, I kind of freak out and got stuck mentally, it's been a long time I hadn't gone without programming.

Now I kind of pick up the rythm again even if I'm no programmer yet


However I was going through a python tutorial because it seems like its everywhere I look for some topic now and while I was doing some code verbatim it seems I had some problem with inheritance for some reason I don't understand.

Code:
class Animal:
    __name = None #"__" mean private
    __height = 0
    __weight = 0
    __sound = 0

    def __init__(self, name, height, weight, sound):#constructor in "__<name>__"
        self.__name = name
        self.__height = height
        self.__weight = weight
        self.__sound = sound

    def set_name(self, name):
        self.name = name
    def get_name(self):
        return self.__name

    def get_sound(self, sound):
        return self.__sound

    def get_type(selfself):
        print("Animal")

    def toString(self):
        return "{} is {} cm tall and {} kg and say {}".format(self.__name,
                                                              self.__height,
                                                              self.__weight,
                                                              self.__sound)

cat = Animal('whiskers', 33, 10, 'meow')
print(cat.toString())

class Dog(Animal):
    __owner =""

    def __init__(self, name, height, weight, sound, owner):
        self.__owner = owner
        super(Dog, self).__init__(name, height, weight, sound)

    def set_owner(self, owner):
        self.__owner = owner
    def get_owner(self):
        return self.__owner

    def get_type(self):
        print("dog")

    def toString(self):
        return "{} is {} cm tall and {} kg and say {} His owner is {}".format(self.__name,
                                                                              self.__height,
                                                                              self.__weight,
                                                                              self.__sound,
                                                                              self.__owner)

    def multiple_sounds(self, how_many=None):
        if how_many is None:
            print(self.get_sound())
        else:
            print(self.get_sound()*how_many)
print("end") #to check where the code 'break'
spot = Dog("spot", 53, 27, "ruff", "derek")
print(spot.toString())

The code correctly printthe cat but does not output the dog for some reason

debug say there is no" __name" ('Dog' object has no attribute '_Dog__name') But the super key word is supposed to take care of that Huh?

Inspecting the class structure does show the existence of inherited name, but apparently he is looking for __dog__name instead of inhert __Animal__name

I'm confused (here is the tut at the right timecode

)

here is a screen capture
https://www.dropbox.com/s/hvki90aepov95wo/Capture%20d%27%C3%A9cran%202015-09-07%2001.16.28.png?dl=0
Logged

TheLastBanana
Level 9
****



View Profile WWW
« Reply #192 on: September 06, 2015, 10:13:19 PM »

In Python, adding two underscores before a variable invokes name-mangling, which is a way of making variables "private" without actually making them private. Basically the variable name is replaced with _<class>__<name>, meaning you're unlikely to accidentally use a private variable from outside the class.

In your example, the variable "__name" will get replaced with "_Animal__name" in the Animal class and "_Dog__name" in the Dog class, so it can't find the variable you're looking for. If you're planning on accessing the variable from subclasses, you should either use only one leading underscore (doesn't do anything fancy, but denotes something like a protected variable) or no underscores (denoting a public variable).

Also, just in case this comes up later, your set_name function is setting the variable self.name instead of self.__name.
Logged
oahda
Level 10
*****



View Profile
« Reply #193 on: September 07, 2015, 02:43:50 AM »

C++. I'm not very savvy when it comes to thread safety and mutexes (mutices?) and all that stuff.

Would it be safe, when an event is called, that might happen in a different thread according to the SDL2 documentation, just to set a boolean to true, and in the main thread check if that boolean is true, do the thing, and set the boolean to false again?

Can that really fail? I mean, a boolean can't be half-set, can it? It's either true when I try to access it or not, right? Not like if I were modifying an array of complex object in a different thread and all the setting was only half-finished in the other thread when I tried to access it in the main thread, right?
« Last Edit: September 07, 2015, 03:18:36 AM by Prinsessa » Logged

zleub
Level 0
**


View Profile WWW
« Reply #194 on: September 07, 2015, 03:10:01 AM »

What if your main thread is reading the boolean at the same time your thread is writing it ?

Here's some doc.
Logged
oahda
Level 10
*****



View Profile
« Reply #195 on: September 07, 2015, 03:16:11 AM »

I was thinking it'd still be either false or true at the same time (and missing the operation by one frame is not important here). Not correct? Can the value ever be invalid? Or does that make for some sort of access violation? Gonna read.

And in either case, what's the simplest solution?
Logged

zleub
Level 0
**


View Profile WWW
« Reply #196 on: September 07, 2015, 03:26:22 AM »

does that make for some sort of access violation?

I would say so, it can depends how stylish is your OS too. The best way is to use the mutex, since it's a tool made right for you issue. Since you're C++, the thread library should possess everything your need. I don't know any better solutions that is not a bandage.
Logged
oahda
Level 10
*****



View Profile
« Reply #197 on: September 07, 2015, 04:00:34 AM »

What do I do if I don't have access to the other thread (hidden somewhere in SDL) and my own operation is to happen in the main thread (i.e. I won't be using std::thread objects at all)? Can I do something like std::this_thread::join() or the like?

Or something along these lines?

Code:
void func_in_main_thread_that_is_callback_to_smth_in_other_thread()
{
    my_mutex.lock();
    my_boolean = true;
    my_mutex.unlock();
}

Sorry, I haven't done much threading. xp
Logged

zleub
Level 0
**


View Profile WWW
« Reply #198 on: September 07, 2015, 04:15:28 AM »

On that FAQ, it's specified that SDL uses thread internally, like you said. Upon that, i'll assume either SDL has made the mutex work (so that you can read your boolean when it's safe to) either gives you callbacks or such to have a way to check mutexes.

What's pretty sure is that SDL is C when you're writing C++, there's no way to just join using C++ API. Here's the SDL thread reference, i guess you could find what you looking for ? It's seems to be some examples here or here.

May i ask which part of your game is threaded and which SDL you're using ?
Logged
oahda
Level 10
*****



View Profile
« Reply #199 on: September 07, 2015, 04:18:46 AM »

I want to add a callback to this:

https://wiki.libsdl.org/SDL_SetEventFilter

And in that callback I want to reset my gamepad/joystick stuff in case any new controller/joystick has been connected or an old one disconnected, so that the game/engine can automatically deal with controllers getting plugged in and out.

And what worries me is, of course, this notice:

Quote
Be very careful of what you do in the event filter function, as it may run in a different thread!



EDIT:
But maybe I can just put it in the event poll that's in the main thread. I'm just worried it might cause trouble similar to this in SFML as I'm guessing at some level SFML and SDL have to be using the same API's to work with this sort of input:

http://forums.tigsource.com/index.php?topic=50222.msg1176681#msg1176681

I'm on Mac so I can't test this seemingly Windows specific problem directly. But I guess I can just do that for now, see how it goes, and then if I do discover horrible lag on Windows later, I'll just change the implementation at that point.

I'm still interested in knowing an answer to my question here, if you have one, tho, just for the sake of learning.



EDIT 2:
Put it in the event poll and it works like a charm on Mac at least. Smiley
« Last Edit: September 07, 2015, 04:28:42 AM by Prinsessa » Logged

Pages: 1 ... 8 9 [10] 11 12 ... 69
Print
Jump to:  

Theme orange-lt created by panic