Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 550 551 [552] 553 554 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 882286 times)

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8265 on: October 23, 2015, 08:01:27 am »

Code: [Select]
auto va = std::make_shared<anim::Vector>(call(static_cast<void(PolygonNode::*)(const sf::Vector2f&)>(&PolygonNode::setPosition), this));

Tries to understand just what the hell is going on...

Code: [Select]
std::make_shared<anim::Vector>(...)Make a shared pointer to an anim::Vector, alright.

Code: [Select]
call(..., ...)Presumably calling some function a with arguments b, yes?

Code: [Select]
static_cast<...>(...)Statically convert something to a new type.

Code: [Select]
void(PolygonNode::*)(const sf::Vector2f&)Brain.exe has stopped working. Some crazy polymorphism and conversion, I'm guessing.

Code: [Select]
&PolygonNode::setPositionAddress of a class static member variable, IIRC. C++ notation is making me dizzy.
« Last Edit: October 23, 2015, 08:05:27 am by da_nang »
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

TheBiggerFish

  • Bay Watcher
  • Somewhere around here.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8266 on: October 23, 2015, 08:17:55 am »

da_nang:
You know much more than I do.
Logged
Sigtext

It has been determined that Trump is an average unladen swallow travelling northbound at his maximum sustainable speed of -3 Obama-cubits per second in the middle of a class 3 hurricane.

3man75

  • Bay Watcher
  • I will fire this rocket
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8267 on: October 23, 2015, 08:45:28 am »

Code: [Select]
auto va = std::make_shared<anim::Vector>(call(static_cast<void(PolygonNode::*)(const sf::Vector2f&)>(&PolygonNode::setPosition), this));

can i change majors

What are you doing here? I recognize std as the std; you type out when you don't use namespace std;. Although tbh I've never made any program without namespace std;.

The loop for the main game seems to be missing from what you pasted there. are you sure it works? It won't compile with your code for me. Always fully test the thing before handing it in, and always after making changes.

I can see you're missing a while loop that needs to go back to the top of the program from the bottom. But basically wherever you put it, you're going to have glitches in the printouts, i can tell you that right now. put up a proper working version here and I'll show you why there are errors.

It did work just fine I'm not sure what happened. Maybe I didn't copy it correctly? I'll resend the whole thing which does have loops. It allowed the user to input their choice of rock-scissors and gave the AI a random choice @start and again should the user decide to play again. All the while if you ever inputed a wrong statement such as a negative or something above 4 it would deny it and re-ask for the information.

An then I had the magical exit button called 4. As far as my teacher said this was what she wanted.
Logged

jaked122

  • Bay Watcher
  • [PREFSTRING:Lurker tendancies]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8268 on: October 23, 2015, 10:16:06 am »

I'm going to guess SFML. That's what namespace sf is, I think... Yes that's what it is. 


But eww... Not exactly sure why you would do that, it's quite... Well... imho It's disgusting syntax. Considering that, I can't think of anything better, you've got that there.


You should figure out something like what's discussed here.


In this case, however, you are creating an animation that alters the position of a given polygon.


On a related note, I've never been convinced that shared_ptrs were anything other than the sort of fluff in the STL that didn't really belong there, but what do I know?

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #8269 on: October 23, 2015, 02:57:13 pm »

But eww... Not exactly sure why you would do that, it's quite... Well... imho It's disgusting syntax. Considering that, I can't think of anything better, you've got that there.
Fake internet points for whoever can, I think that might be as good as it gets.

Spoiler: Explanation (click to show/hide)

Other uses of this function, without overloaded member function nonsense, look like this:
Code: [Select]
auto vax = std::make_shared<anim::Color>(call(&PolygonNode::setFillColor, this));
Basically, one of these animation constructors takes only one argument: a callback function. The function here needs to take a single sf::Color value, so this animation just interpolates between two or more colors in sequence. Then I define keyframes that it cycles through, like this:
Code: [Select]
KeyFrame<sf::Color> kf(anim::Color::interpolateLinear, sf::seconds(1.0f), sf::Color::Red);
This creates a keyframe with embedded color data. This constructor makes a keyframe that linearly interpolates between the previous color and the color red over the course of 1.0 seconds. That first argument is a function pointer; I have functions for linear and cosine interpolation, and could make any number of other algorithms in addition to those.


This is what over-engineering looks like.
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

jaked122

  • Bay Watcher
  • [PREFSTRING:Lurker tendancies]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8270 on: October 23, 2015, 05:59:02 pm »

Would you mind posting how you store the values that the polygon moves to and from? I'm a bit curious, also I'd like to see the architecture because it's actually something I can imagine myself using.




Also relevant to the thread, Rust is really... Different.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8271 on: October 23, 2015, 08:18:55 pm »

Have you looked at d3.js? It also has transitions, but in a very different form. Could be something to draw inspiration from.
.

Then again, javascript uses asynchronous calls a lot and is also sloppy.
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Putnam

  • Bay Watcher
  • DAT WIZARD
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8272 on: October 23, 2015, 08:37:51 pm »

javascript isn't sloppy, it's just that everybody has an idea on how to write libraries for it

Gatleos

  • Bay Watcher
  • Mournhold... City of Light... City of MAGIC!
    • View Profile
    • Someone Sig This
Re: if self.isCoder(): post() #Programming Thread
« Reply #8273 on: October 23, 2015, 10:10:53 pm »

Would you mind posting how you store the values that the polygon moves to and from? I'm a bit curious, also I'd like to see the architecture because it's actually something I can imagine myself using.

Sure. The keyframe values look like this (member functions excluded):
Code: [Select]
template <class T>
class KeyFrame {
public:
sf::Time duration;
T data;
bool relative;
const std::function<T(const T& a, const T& b, const float& val)> getVal;
};

Each has a duration measured in microseconds, a boolean value that specifies if the value is relative or absolute, and a "data" field that has a templated type. It also has a templated function object; this function just returns an interpolated value based on 2 inputs. This is where it determines whether to use linear interpolation, cosine, an instant switch, etc.

Code: [Select]
template <class T>
class KeyFrameList {
std::list<KeyFrame<T>> frames;
bool playing;
bool looping;
T relData;
T currentData;
T* nextData;
typename std::list<KeyFrame<T>>::iterator itNext;
sf::Time currentTime;
float timeRatio;
};

This class contains a list of those keyframes, and has functions that loop through them. The animation can play through once or loop. The values in the keyframe list don't change once they're initialized, but since a value can be relative and thus needs to be calculated from the previous one, there's another data field to store that relative value (relData).

Every loop, the current progress in the animation is calculated. Then it makes a call to the interpolation function stored in nextData->getVal, using the current values as inputs (timeRatio is a value in the range [0.0, 1.0) ):
Code: [Select]
itNext->getVal(currentData, *nextData, timeRatio);
Logged
Think of it like Sim City, except with rival mayors that seek to destroy your citizens by arming legions of homeless people and sending them to attack you.
Quote from: Moonshadow101
it would be funny to see babies spontaneously combust
Gat HQ (Sigtext)
++U+U++ // ,.,.@UUUUUUUU

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8274 on: October 24, 2015, 01:04:54 am »

javascript isn't sloppy, it's just that everybody has an idea on how to write libraries for it
By sloppy, I mean the type system. C++ needs a looot of templates partially because it can't have arbitrary types, right?

(Also, d3.js is the superior library :V I am a little tempted to try out underscore.js but eh)
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8275 on: October 24, 2015, 12:17:01 pm »

JavaScript's language design in general is sloppy in my opinion.  I'm sure many of you have seen the websites that show the very surprising results of some unusual arithmetic operations in JavaScript.  It's well defined by the standard, but the design decisions are just strange in some cases.

And yes, the type system is sloppy and surprising in some cases.  Trying to get the type of something in JavaScript is complicated.  If I remember right a string can have two different types depending on whether you created the string as a literal (''a string") or with the String constructor (new String("a string")).

I'd complain about the class system again, but I wouldn't say that it's sloppy so much as strange and kind of a bad idea.  Prototypal inheritance is kind of neat, but the fact that classes are just functions that you have to treat specially is prone to problems.  Don't forget the "new" keyword, or you'll have fun debugging sessions ahead of you.
Logged
Through pain, I find wisdom.

itisnotlogical

  • Bay Watcher
  • might be dat boi
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8276 on: October 24, 2015, 10:03:46 pm »

I've tried Javascript, and I have to say that canvasses are probably the only low-level graphics thing that doesn't make me want to curl up in a ball and die. Classes in JS are a pain in the ass though.



I hate Unity's input manager. Unless I'm missing something, you have to create two input fields to support both keyboards and joysticks. Joystick axes and keyboard input absolutely cannot be mixed, so you have to create four axes: keyboard horizontal and vertical, and joystick horizontal and vertical. It's stupid and dumb but god dammit I've spent years on Unity so that's my lot.
Logged
This game is Curtain Fire Shooting Game.
Girls do their best now and are preparing. Please watch warmly until it is ready.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8277 on: October 24, 2015, 10:19:36 pm »

The (only?) redeeming part about Javascript is that it teaches you how great callback functions are :v I find that I never ever make my own classes, since it's easier to treat everything as a plain old data object and put the logic in the functions. This is especially true with Underscore.js, which gives you all the nice functions you expect from using Python, like zip() and map() and each() <since for (x in y) in JS is pretty weird> ...

I guess another redeeming feature is that it's fairly quick and easy to make functional GUI programs in Javascript plus HTML. Needs a framework like jQuery or (my favorite) d3.js to actually do that though...
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward

Telgin

  • Bay Watcher
  • Professional Programmer
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8278 on: October 24, 2015, 11:46:25 pm »

I've found relatively few reasons to create classes either, and quite often do the same thing.  The ability to write out object literals is definitely one of the things I do like the best about JavaScript though, especially as compared to PHP.

Code: [Select]
var some_object = {
    property: 'value',
    some_function: function() {
        return 'another value';
    }
};

That's so very convenient and does largely replace the need for classes.  Classes are really only needed if you need inheritance, which is again something I rarely find a need for.

In PHP you have to do something awful like this:

Code: [Select]
$some_value = (object)array(
    'property' => "value"
);

But you can't just define a function inline like that at all, and have to assign it after creating the object.  I find it kind of funny that PHP has array literal syntax like this that can be cast to an object, but has no object literal syntax.  They had a proposal to add object literal syntax of some kind (JSON was rejected I think), but it never went anywhere.

It's been a while since I've touched Python, but I don't think it can do that either.  Its equivalent functionality was dictionaries I think?  I don't think you can define functions directly on a dictionary, but you can probably assign them to dictionary keys somehow.
Logged
Through pain, I find wisdom.

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #8279 on: October 25, 2015, 12:16:05 am »

Yeah, you can assign functions as values. Keys have to be hashable.

There are no anonymous functions, only lambdas (which are one line only), so you have to define stuff outside of the dictionary. eg,

def foo():
   return 0;

dictionary = {"foo":foo}
dictionary["foo"]()

If this was javascript, you could have done dictionary.foo()! But, if you're doing python you might as well use a class, they're pretty nice :v

edit: I really love underscore.js... it's a dash of Python-y functional functions (intersection, map, reduce, each) in JS <3
« Last Edit: October 25, 2015, 05:07:13 am by Skyrunner »
Logged

bay12 lower boards IRC:irc.darkmyst.org @ #bay12lb
"Oh, they never lie. They dissemble, evade, prevaricate, confoud, confuse, distract, obscure, subtly misrepresent and willfully misunderstand with what often appears to be a positively gleeful relish ... but they never lie" -- Look To Windward
Pages: 1 ... 550 551 [552] 553 554 ... 796