Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 209 210 [211] 212 213 ... 796

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

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3150 on: October 22, 2012, 06:43:58 am »

But... killing puppies is a good thing!

Anyway, you can just use a static or singleton and then pretend you're not using globals. Even though it's generally the same thing.
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))

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3151 on: October 22, 2012, 06:50:40 am »

Hmm... well, I use a single global struct to handle all the passing of data to other classes in my project, because I'm too lazy to make a "better" implementation.


I have another peculiar problem. It's involving the debug vs release build modes of Visual Studio. Debug mode works fine, but it's dependent on DLLs like msvcr100d.dll which only come with Visual Studio, not with the C++ redistributable. Also, from a quick google search, it says Debug mode doesn't optimize code.
On the other hand, Release mode throws a ton of errors. D:

Code: [Select]
1>Baseclass.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall TCODConsole::putChar(int,int,int,enum TCOD_bkgnd_flag_t)" (__imp_?putChar@TCODConsole@@QAEXHHHW4TCOD_bkgnd_flag_t@@@Z)
1>Baseclass.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall TCODConsole::setCharForeground(int,int,class TCODColor const &)" (__imp_?setCharForeground@TCODConsole@@QAEXHHABVTCODColor@@@Z)
1>Baseclass.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall TCODConsole::setCharBackground(int,int,class TCODColor const &,enum TCOD_bkgnd_flag_t)" (__imp_?setCharBackground@TCODConsole@@QAEXHHABVTCODColor@@W4TCOD_bkgnd_flag_t@@@Z)
1>Engine.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static void __cdecl TCODConsole::blit(class TCODConsole const *,int,int,int,int,class TCODConsole *,int,int,float,float)" (__imp_?blit@TCODConsole@@SAXPBV1@HHHHPAV1@HHMM@Z)
1>Engine.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall TCODConsole::clear(void)" (__imp_?clear@TCODConsole@@QAEXXZ)
1>PODS.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: virtual __thiscall TCODConsole::~TCODConsole(void)" (__imp_??1TCODConsole@@UAE@XZ)
1>PODS.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall TCODConsole::TCODConsole(int,int)" (__imp_??0TCODConsole@@QAE@HH@Z)
1>PODS.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: void __thiscall TCODConsole::setDefaultBackground(class TCODColor)" (__imp_?setDefaultBackground@TCODConsole@@QAEXVTCODColor@@@Z)
1>PODS.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class TCODColor const TCODColor::black" (__imp_?black@TCODColor@@2V1@B)
1>PODS.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class TCODColor const TCODColor::yellow" (__imp_?yellow@TCODColor@@2V1@B)
1>PODS.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall TCODColor::TCODColor(int,int,int)" (__imp_??0TCODColor@@QAE@HHH@Z)
1>PODS.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: __thiscall TCODColor::TCODColor(void)" (__imp_??0TCODColor@@QAE@XZ)
1>TCODEngine.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static void __cdecl TCODConsole::flush(void)" (__imp_?flush@TCODConsole@@SAXXZ)
1>TCODEngine.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static void __cdecl TCODConsole::setCustomFont(char const *,int,int,int)" (__imp_?setCustomFont@TCODConsole@@SAXPBDHHH@Z)
1>TCODEngine.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static void __cdecl TCODConsole::initRoot(int,int,char const *,bool,enum TCOD_renderer_t)" (__imp_?initRoot@TCODConsole@@SAXHHPBD_NW4TCOD_renderer_t@@@Z)
1>TCODEngine.obj : error LNK2001: unresolved external symbol _SDL_PollEvent
1>TCODEngine.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static void __cdecl TCODSystem::setFps(int)" (__imp_?setFps@TCODSystem@@SAXH@Z)
1>TCODEngine.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: static class TCODConsole * TCODConsole::root" (__imp_?root@TCODConsole@@2PAV1@A)
1>TCODEngine.obj : error LNK2001: unresolved external symbol _SDL_Quit
1>MSVCRT.lib(crtexe.obj) : error LNK2001: unresolved external symbol _main
1>C:\Users\Administrator\Documents\Visual Studio 2010\Projects\ASCII sandbox\Release\ASCII sandbox.exe : fatal error LNK1120: 20 unresolved externals

I can only make out gibberish Dx Any help?

Or ways to make a build that optimizes code and isn't dependent on debug libraries like the above-mentioned -d suffixed dll?

If not optimization, at least not being dependent.
I'm using libtcod and SDL, btw.
« Last Edit: October 22, 2012, 08:34:51 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

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #3152 on: October 22, 2012, 06:58:13 am »

I tend to favour a service layer with dependencies to services injected at construction. Really useful way of handling dependencies in a none-global reusable manner. Not perfect but very flexible.

Also much easier to test and TDD if you care about that.
« Last Edit: October 22, 2012, 07:01:17 am by MorleyDev »
Logged

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3153 on: October 22, 2012, 09:05:04 am »


I have another peculiar problem. It's involving the debug vs release build modes of Visual Studio. Debug mode works fine, but it's dependent on DLLs like msvcr100d.dll which only come with Visual Studio, not with the C++ redistributable. Also, from a quick google search, it says Debug mode doesn't optimize code.
On the other hand, Release mode throws a ton of errors. D:

I'm using libtcod and SDL, btw.
Check through your project properties for release mode. Often times the libraries/other options won't carry over from the debug setting to the release setting. Change the configuration you are viewing from the dropdown menu in the upper-left, then go through and check for the libraries you are using. By the looks of it, libtcod isn't being linked correctly.
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #3154 on: October 22, 2012, 09:08:02 am »

Ahhhhh. Excellent, thanks! :D

Also, sorry for clogging up the thread with all my questions Dx
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

GalenEvil

  • Bay Watcher
    • View Profile
    • Mac-Man Games
Re: if self.isCoder(): post() #Programming Thread
« Reply #3155 on: October 22, 2012, 01:28:02 pm »

But... Skyru! This is a Q&A thread of sorts :D all questions are good questions >.>
Logged
Fun is Fun......Done is Done... or is that Done is !!FUN!!?
Quote from: Mr Frog
Digging's a lot like surgery, see -- you grab the sharp thing and then drive the sharp end of the sharp thing in as hard as you can and then stuff goes flying and then stuff falls out and then there's a big hole and you're done. I kinda wish there was more screaming, but rocks don't hurt so I guess it can't be helped.

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3156 on: October 22, 2012, 01:47:01 pm »

Here's a question - what's a good way to approach classes and object handling in js?

I've seen several different approaches, and I'm honestly not sure which to use (or even under which situation, if there are different reasons to use them).

Right now I'm going with a sort of factory-based structure, I guess? So I get:

Code: [Select]
function myClass(Thing){
  Thing.stuff = 4;
  Thing.method = function(){ return (Thing.stuff + Thing.value) };
 
  return Thing;
}

var myObject = myClass({value: 9});
myObject.method()  // Should return 13

But for all I know this is an absolute stupid way to handle this stuff. And the inheritance handling they it be pretty primitive for that approach. Any suggestions here on a better approach?

My javascript up until this point has mainly been logic and view manipulation, and mostly working through jQuery - this is the first time I've really messed with the structural components.
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3157 on: October 22, 2012, 02:10:17 pm »

The best thing to do is to embrace the js prototyping object oriented approach.

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.

da_nang

  • Bay Watcher
  • Argonian Overlord
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3158 on: October 22, 2012, 02:13:52 pm »

Care to extrapolate on "approaching" classes? If you mean designing them, there's UML. Use class diagrams, state charts and be clever with design patterns where suitable (but don't go nuts with them).
Abstraction and modularity are your friends, or so I've been told. If an attribute of a class can't be defined as a primitive data type or string, then it's probably better to give it its own class.
Logged
"Deliver yesterday, code today, think tomorrow."
Ceterum censeo Unionem Europaeam esse delendam.
Future supplanter of humanity.

Siquo

  • Bay Watcher
  • Procedurally generated
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3159 on: October 22, 2012, 02:42:27 pm »

This should work, right? I'm getting some weird different numbers if I try it, though :(
Spoiler (click to show/hide)

Edit: DOH, of course &vector doesn't work, it's a wrapper. I needed vector.data() for the pointer...
« Last Edit: October 22, 2012, 04:27:37 pm by Siquo »
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))

GlyphGryph

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3160 on: October 22, 2012, 03:16:11 pm »

Care to extrapolate on "approaching" classes? If you mean designing them, there's UML. Use class diagrams, state charts and be clever with design patterns where suitable (but don't go nuts with them).
Abstraction and modularity are your friends, or so I've been told. If an attribute of a class can't be defined as a primitive data type or string, then it's probably better to give it its own class.

No, no, I'm good enough at all that abstract stuff, I'm just concerned about actual literal implementation. Javascript doesn't actually have classes (no class, whatsoever) - you need need to sort of build your own class system to program that way. It's all object inheritence, so "classes" end up being factories or something, there's multiple ways to implement it.

It's kind of like Ruby in that way (Ruby also doesn't have actual classes), but ruby does a much better job of pretending. :P

I'm actually a fairly good programmer when it comes to general structure and flow, but I fall down hard on things like syntax and language-level details. And terminology, I'm bad at that too.
« Last Edit: October 22, 2012, 03:23:58 pm by GlyphGryph »
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3161 on: October 22, 2012, 03:20:33 pm »

prototyping is merely a different way of approaching OOP without classes. You don't need to reinvent classes in js.
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 #3162 on: October 22, 2012, 03:28:43 pm »

At least I've finally figured out that it is, in fact, different from capital P "Prototype", which is awful, and was causing me to filter out any blurbs about prototype mentally.

But what is the actual advantage of the prototype approach as opposed to simply using a function to define them? Just smaller objects?

I'm assuming there's more to prototype stuff than what I've read so far, though, something to differentiate it more than that.
« Last Edit: October 22, 2012, 03:33:16 pm by GlyphGryph »
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #3163 on: October 22, 2012, 03:50:06 pm »

With prototyping, you can change the prototype definition and it can update all objects with that prototype. It also means that until an objects inherited member is modified, it exists with the prototype default value and doesn't actually consume any memory.
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 #3164 on: October 22, 2012, 03:52:05 pm »

Care to expound on the use of the first bit? I'm not saying the cases where that ability would come in useful.

The performance abilities of the second might not be terribly important on my current project, but never hurt really.
Logged
Pages: 1 ... 209 210 [211] 212 213 ... 796