Jump to content

  • Log In with Google      Sign In   
  • Create Account


Telastyn

Member Since 13 Oct 2003
Offline Last Active Jul 18 2014 06:13 AM
*****

Posts I've Made

In Topic: Modifying my own code while it's running

03 January 2014 - 09:24 PM

Enh, up I imagine the runtime modification would screw up your profiling more than simply including it always (in beta) and turning on logging when needed. When done judiciously, it won't substantially impact performance but still give you plenty of instrumentation to identify issues.

In Topic: Modifying my own code while it's running

03 January 2014 - 09:07 PM

You're better off using an aspect oriented programming framework like PostSharp to inject these things during a build step rather than at runtime. I'm not sure how viable ubiquitous runtime modification of a loaded assembly is.

In Topic: Having trouble accessing an objects properties.

25 December 2013 - 09:06 AM

The solution is to not need BladeWarrior's methods to fight. Generally that means making common methods available on character, making BladeWarrior an instance of Character (rather than a derivative of it), or by letting the thing that controls the fighting get a BladeWarrior rather than a Character array (though that one depends a lot more on how your game works).

In Topic: Code Review - Event Use?

30 November 2013 - 05:59 PM


I know it would work fine, but in the interest of the single responsibility principle, would it be ok?

 

But it has a single responsibility: to allocate power to a subsystem. It knows how to tie the various other single responsibilities together. Something has to do that after all.

 

It might be good to separate that responsibility from the power source, but I'm not sure the decoupling benefits (flexibility, testability) here are worth the downsides (more overhead, harder to implement/read/maintain).


In Topic: Code Review - Event Use?

30 November 2013 - 08:35 AM


The only other way I see writing this is if I pass instances of the relay, warp core, and subsystem to each other.

 

Yes, that seems to be the obvious thing to do.

 


Feels over kill

 

Just passing things around is the simplest, most straightforward way to code. It should be your default approach until you have some requirement (there may or may not be something passed in, there may be N things passed in at any given time, there may be things in weird plugins we don't know about).

 

I don't know your requirements but I would approach it like this:

public interface Subsystem {
        bool IsPowered { get; }
        int MaxPower { get; }
        int PowerLevel { get; }
    }

    public interface PowerSource {
        int SuppliedPower { get; }
        IEnumerable<KeyValuePair<Subsystem, int>> PowerAllocation { get; }
        void AllocatePowerToSubsystem(Subsystem target);
    }

If you can't simply allocate any subsystem to any power source, the Allocate method may need to be in a higher level "Ship" object. Either way, the entire logic for that operation lives in the one method devoted to doing it - not spread across 6 event handlers which provide no benefit.


PARTNERS