Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 168 169 [170] 171 172 ... 796

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

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2535 on: June 17, 2012, 06:58:39 pm »

Thank Ogd for GUI builders :P

Yes... Though I have come to loathe visual studios gui builder. It may be one of the best in the business, but it is still terribly buggy.

If there was a decent gui builder for eclipse this would be a java project instead of a c# project.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2536 on: June 17, 2012, 06:59:23 pm »

What's so silly about programming a roguelike in Ruby?

I guess you could use the c++ visual libraries without too much trouble, but its not exactly super fun and last I checked ruby visual libraries were crap. Plus there's the whole hassle of getting it to run on other people's computers, though that might just be personal experience - there's probably a way to package it up to make it easy, but hell if I know how to do it.

I guess it's an option, at least.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2537 on: June 17, 2012, 07:39:22 pm »

I have no idea as to what you're trying to do...

Gatling gun inherits armpart's values, and armpart inherits frameparts values, but never will armpart inherit gatlingguns' values. You'll also need to call "set" on the plarm, btw.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2538 on: June 18, 2012, 02:55:53 am »

I would like to instantiate an arbitrary class in C++. I know how to do this in C#:

Code: [Select]
T Instantiate<T>() where T : new(){
     
     T instance = new T();
     
     return instance;
     
}

The above code creates an instance of the type passed to it. If you wanted to make a Ball, it would work like this:

Code: [Select]
Ball b = Instantiate<Ball>();


How do I do this with C++? I am aware of templates, but there has to be a better way.
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2539 on: June 18, 2012, 03:18:58 am »

How do I do this with C++? I am aware of templates, but there has to be a better way.
Not that I (intermediate C++ experience) know of. And what is so bad about templating that function? Unless you're in some kind of 64k demo contest, the multiple copies won't be that much of a strain on your resources...
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2540 on: June 18, 2012, 03:36:16 am »

So apparently I can just do "new T", like this:

Code: (C++) [Select]
template<typename T>
T Instantiate(){
     
     return *(new T);
     
}

That's useful, but it's just part of what I'm doing. What if I want to compare if a variable is of a certain type? In C# it looks like this:

Code: (C#) [Select]
bool Test<T>(){
     
     Ball ball = new Ball();
     
     return ball is T;
     
}
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2541 on: June 18, 2012, 03:54:55 am »

So apparently I can just do "new T", like this:
Yep, that's what I meant. Now you can cast the new T into Ball to check the class, OR overload&specialise the template, but there's a lot of "buts" and "only-ifs" connected to that, and I know I don't know all of them, function template specialisation is advanced;)
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2542 on: June 18, 2012, 04:12:57 am »

Your first link got me going in the right direction. Thanks!

I think these two lines are basically the same:

Code: (C#) [Select]
if(Ball is T)

Code: (C++) [Select]
if(typeid(Ball) == typeid(T))
Logged

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2543 on: June 18, 2012, 04:28:23 am »

I do not know what "is" does, but keep in mind that typeid does an exact match, and that derived classes such as class Football : public Ball{} will not match. For that you'd need the second example in that first link with dynamic_cast.
Logged

This one thread is mine. MIIIIINE!!! And it will remain a happy, friendly, encouraging place, whether you lot like it or not. 
will rena,eme sique to sique sxds-- siquo if sucessufil
(cant spel siqou a. every speling looks wroing (hate this))

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2544 on: June 18, 2012, 02:09:02 pm »

Does anyone know of any good OCR libraries for c#?

I found this: http://www.pixel-technology.com/freeware/tessnet2/

but I don't know if will be able to pull data from diablo 3 screenshots yet.
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2545 on: June 18, 2012, 05:18:53 pm »

Venting about c++ ahead! 'Cause I feel like it.

Two things I loathe about it:

1) No easy way to maintain local scope and eliminate redundancy. If you've a function that does the same identical block of code multiple times throughout, the normal way to eliminate redundancy is to turn that block of code into a function call. This means you lose local scope. The ways around this are 1) Pass your local variables as arguments (sloppy), 2) Turn your locals into globals (retch), or 3) use macros (potentially long compile times, ahoy!). I've started gravitating toward globals and I feel dirty.

2) Switch statements are horrible. Note that state machines are my bread and butter when it comes to coding object behavior in games. The normal response to people using switch statements is "use polymorphism!" but that's not an option when I want my enemy to choose from 100 different possible behaviors. I'm not gonna have 100 identical classes save their behavior subroutine. Oh how I wish for a switch statement without a default case, so it didn't have to be an if/else chain on the assembly level (which gets much slower the more cases you have. Not good when you want hundreds if not thousands of objects active.).



I guess I was spoiled by assembly where neither of those were problems.
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2546 on: June 18, 2012, 05:30:38 pm »

Yeah, I get that.  c++ needs closures badly.  Then you wouldn't need to worry about losing local scope.
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2547 on: June 18, 2012, 05:40:26 pm »

Kaijyuu, I really would pass local variables to the function way way before using globals.
Also C++11 has anonymouse functions you should be able to define in scope, but I have not really looked at them.

You can also create an alternative to the switch statement that can match an arbitrarily large number of cases much faster than O(N).

Step 1: create a dictionary/vector using your favorite collections library. The keys are cases to be switched, the values are function pointers/objects to the method to execute in each case.

Step 2: instead of doing a switch, pull the function from the dictionary/vector using the value and then execute that function.

There you have a switch with execution time that scales with the efficiency of your dictionary, most likely O(log(2)N).


Edit: its a bit of a pet peeve of mine when people call anonymous functions closures. They are not really the same thing even though an anonymous function can be a closure and a closure can be an anonymous function. This pet peeve is further annoyed because always assume that closure refers to syntactic closure.

http://en.wikipedia.org/wiki/Syntactic_closure
« Last Edit: June 18, 2012, 05:46:25 pm by Nadaka »
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.

Levi

  • Bay Watcher
  • Is a fish.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2548 on: June 18, 2012, 05:52:03 pm »

Edit: its a bit of a pet peeve of mine when people call anonymous functions closures. They are not really the same thing even though an anonymous function can be a closure and a closure can be an anonymous function. This pet peeve is further annoyed because always assume that closure refers to syntactic closure.

http://en.wikipedia.org/wiki/Syntactic_closure

Heh, sorry.  I've never been good with terminology.   :)
Logged
Avid Gamer | Goldfish Enthusiast | Canadian | Professional Layabout

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2549 on: June 18, 2012, 05:54:19 pm »

Like I said, its a pet peeve. I know the amount of annoy I get is at least a bit irrational. :)
Logged
Take me out to the black, tell them I ain't comin' back...
I don't care cause I'm still free, you can't take the sky from me...

I turned myself into a monster, to fight against the monsters of the world.
Pages: 1 ... 168 169 [170] 171 172 ... 796