Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 ... 183 184 [185] 186 187 ... 796

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

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #2760 on: August 15, 2012, 05:56:33 pm »

I wanted to say "May your kills be quick and many" but didn't think it applied to this situation for some reason ;D
« Last Edit: August 15, 2012, 06:11:36 pm by MorleyDev »
Logged

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2761 on: August 15, 2012, 06:00:39 pm »

I wanted to say "May your kills be quick and many" but didn't think it applied to this situation for some reason ;D

It does, more than you could imagine.

You have not seen the code of the guy who is going on Monday. It should be an SCP. Keter class.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #2762 on: August 15, 2012, 06:12:40 pm »

Found a Fun article for all you PHP fanatics.

Hmm, actually can I get opinions on something. At work (C#) we were hesitant to involve an Aspect Oriented Programming framework to handle our cross-cutting concerns (the timing of live http end points and security being the main two cross-cutters we're dealing with atm). We've been essentially 'faking' it in out latest iterations by creating "proxy" implementations of the same (or "secure" versions of) the interfaces that add the desired security checks before the actual function calls.

Now, I've realised we're basically (if you take this to it's logical and generic library of a conclusion) doing what Spring.NET does to provide 'AOP' in a very manual way. Anybody have any other suggestions?

At the moment our code is doing things like
Code: [Select]
class ClassQueryDatabaseForSomething : IDatabaseQueryingThing
{
    public ValueInDatabase GetThingFromDatabase(UserId userId)
    {
        return _databaseService.GetDBStuff(userId);
    }
}

class SecureClassQueryDatabaseForSomething : ISecureDatabaseQueryingThing
{
    public ValueInDatabase GetThingFromDatabase()
    {
        var userId = _userService.GetCurrentUser();
        _securityService.CheckUserAuthorisation(userId);
        return _actualImplementation.GetThingFromDatabase(userId);
    }
}

class SecureQueryDatabaseFactory
{
    public static ISecureDatabaseQueryingThing CreateDatabaseQueryThing()
    {
        var databaseQueryThing = UnsecureQueryDatabaseFactory.CreateDatabaseQueryThing();
        return new SecureClassQueryDatabaseForSomething(databaseQueryThing);
    }
}

It's a bit tedious and we're investigating into less tedious solutions, because we're programmers and we're lazy like that :) Spring.NET looks neat but makes the factories more involved and complex by it's nature, and whilst obviously you have things like PostSharp, they tend to do Postprocessing and we're a little hesitant to say the least...

*sigh* I wonder if they'll ever add proper AOP support to Attributes in .NET...that'd be sweet.
« Last Edit: August 15, 2012, 06:52:18 pm by MorleyDev »
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2763 on: August 15, 2012, 07:03:30 pm »

Maybe I am getting old, but I just don't get aspect oriented programming. It just sounds like a way to obfuscate shit that shouldn't be obfuscated.
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.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #2764 on: August 15, 2012, 07:12:22 pm »

It exists pretty much entirely for maintaining modularity when faced with annoying cross-cutting concerns which don't really have any other clean solutions at the moment. So long as you're explicitly 'tagging' things you can still easily see what it does and isn't any more obfuscated than say an interface or function pointer but with the added benefit of not having to explicitly inject them everywhere as dependencies on each class.
« Last Edit: August 15, 2012, 07:16:56 pm by MorleyDev »
Logged

Nadaka

  • Bay Watcher
    • View Profile
    • http://www.nadaka.us
Re: if self.isCoder(): post() #Programming Thread
« Reply #2765 on: August 15, 2012, 07:25:00 pm »

How do you "tag" something without injecting a dependency or using some kind of preprocessor?
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.

MorleyDev

  • Bay Watcher
  • "It is not enough for it to just work."
    • View Profile
    • MorleyDev
Re: if self.isCoder(): post() #Programming Thread
« Reply #2766 on: August 15, 2012, 07:32:46 pm »

Well I guess the 'ideal' solution a new version of .NET could include would look something like...

Code: [Select]
public class PulseTimed : IBeforeAspect, IAfterAspect
{
    public PulseTimed(string name)
    {
        _name = name;
    }

    public void Before(object[] parameters)
    {
        _stopWatch.Start();
    }

    public void After(object result)
    {
        _stopWatch.Stop();
        _pulseClient.RecordTime(_name, _stopWatch.GetTime());
    }
}

public class SecureUser : IBeforeAspect
{
    public UserId CurrentUser { get; set; }

    public void Before(object[] parameters)
    {
         var userId = _userService.GetCurrentUser();
         _securityService.CheckAuthorised(userId);
         CurrentUser = userId;
    }
}

public class DatabaseQueryingThing : IDatabaseQueryingThing
{
    [SecureUser]
    [PulseTimed("DatabaseQueryingThing")]
    public ValueInDatabase GetThingFromDatabase(UserId userId = SecureUser.CurrentUser)
    {
        return _repository.SelectFromDatabaseSomeValueForUser(userId);
    }
}

All of these methods'll achieve pretty much the same thing, it's just obsessing over effort, neatness, reusability really. And maintainability. That ones rather important...
« Last Edit: August 15, 2012, 07:51:11 pm by MorleyDev »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2767 on: August 15, 2012, 09:38:41 pm »

So ... is the idea of running through a vector of classes as part of a loop ... wrong?

Say, in a board game, there is a vector list of the class Board, from which all the classes in the list inherit from. That Board class has the function mainf() which is virtual and redefined by each class to their own. So one class in the vector calculated the waves, the next comprehends the input, another does unit1's AI, the next unit2's AI, and so on; then at the very end things like hits are calculated and the actual graphics are updated. o.O
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

dreadmullet

  • Bay Watcher
  • Inadequate Comedian
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2768 on: August 15, 2012, 10:04:33 pm »

So ... is the idea of running through a vector of classes as part of a loop ... wrong?

No. Whatever works for you just go with it. As for your specific implementation, there's nothing absurd about it. I'm pretty certain I've implemented something very similar before. But I don't comprehend why you named the base class "Board". A name I would use is "Behaviour" or "Updater".
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2769 on: August 15, 2012, 10:09:48 pm »

Well, I suppose it's because I have trouble naming stuff, and also because the list contains (or rather will contain) all of the stuff related to the board, such as projectile courses (which are drawn to the board, of course), or unit positions, or ...

Yeah, I have trouble naming stuff. <.<

I have only the smallest dreams for that program, such as actually drawing a cursor, or making the wave background work, but a certain error I believe might be because of #pragma once or the diamond problem made me ragequit it because it was late, and it's been two weeks since. :3
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

alway

  • Bay Watcher
  • 🏳️‍⚧️
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2770 on: August 15, 2012, 10:15:47 pm »

Yeah, the naming convention is a bit weird, but overall the system itself isn't too bad. It could be a real pain if you are adding/moving/removing things from that list, particularly if done so in different areas in code, but so long as you are able to keep straight in your mind what is running and when, it should work relatively well. It would sort of shift your program away from a typical object oriented hierarchy of 'this class contains all these other classes, and calls their update functions when its update function is run.' Depending on how you use it, that could be a good or a bad thing. Adding a few dependency flags would allow such a system to distribute the workload to multiple threads with little additional effort.

As for quitting work on a program for a period of time, there's a reason I named my recent project 'Fjord.' It's something carved out over eons of activity moving at a glacial pace. :P
« Last Edit: August 15, 2012, 10:17:59 pm by alway »
Logged

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2771 on: August 15, 2012, 10:29:03 pm »

I wonder what multithreading is. o.O I have no inkling of how it would work and why xD

If it's running two bits of code at the same time, I could see where it can be used to make things quicker. :S For example, the wave-updating code is completely arbitrary to the rest of the code and could be calculated while the main program does Other Stuff.
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

DrKillPatient

  • Bay Watcher
  • The yak falls infinitely
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2772 on: August 16, 2012, 12:17:23 am »

I've got a logical problem. Programming related, but not language specific (although I'm using C++, if that helps).

I have a game with an animated title screen, which renders in a while-loop, and which exits if the user has quit. It's structured somewhat like this (pseudocode):

Code: [Select]
while (user has not quit)
    clear the display
    process and render the title screen to the display
    if (user has pressed a key)
        open a menu
(Each submenu is also rendered and calculated using a basically the same process.)

Certain windows (opened by a keypress from the if-statement) may pop up to cover the title screen, but not completely. While they are open, the title screen's loop does not continue, and so the animation freezes while another window is opened from within the if-statement.

How would I need to change this code's structure so that the title screen can still animate while a menu is open?
« Last Edit: August 16, 2012, 12:24:33 am by DrKillPatient »
Logged
"Frankly, if you're hanging out with people who tell you to use v.begin() instead of &v[0], you need to rethink your social circle."
    Scott Meyers, Effective STL

I've written bash scripts to make using DF easier under Linux!

Skyrunner

  • Bay Watcher
  • ?!?!
    • View Profile
    • Portfolio
Re: if self.isCoder(): post() #Programming Thread
« Reply #2773 on: August 16, 2012, 02:00:31 am »

In my programs, which use an engine made by Gat, the rendering is done separately from the logic. So the entire thing would loop like thus:

Code: [Select]
Initialize.
Start loop-
  Get input.
  Do logic.
  Render.
End loop.

So you would get the key input "k" which goes on an if-tree to toggle a bool 'submenu_is_open'. That bool is sent to Render, so the title is rendered, then above it the sub-menu.
The next loop around, the input is accepted again—say, I pressed 'down'. The input is passed to the logic stage, except this time the 'submenu_is_open' bool sends the input into another if-tree and is processed. Again, the title is rendered and above it the submenu.

Not sure if optimal or not. Each loop is a frame.
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

Valid_Dark

  • Bay Watcher
  • If you wont let me Dream, I wont let you sleep.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2774 on: August 16, 2012, 05:18:22 am »

I wonder what multithreading is. o.O I have no inkling of how it would work and why xD

If it's running two bits of code at the same time, I could see where it can be used to make things quicker. :S For example, the wave-updating code is completely arbitrary to the rest of the code and could be calculated while the main program does Other Stuff.

read this
http://computationaltales.blogspot.com/2011/06/bog-dragons-do-not-support.html
Logged
There are 10 types of people in this world. Those that understand binary and those that don't


Quote
My milkshake brings all the criminals to justice.
Pages: 1 ... 183 184 [185] 186 187 ... 796