Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 06 Oct 2006
Offline Last Active Yesterday, 10:33 PM

Posts I've Made

In Topic: c++: sprintf but return chars. Possible?

Yesterday, 10:50 AM

If you're just looking for nice c++ string formatting, I recommend fmt.


fmt (formerly cppformat) is an open-source formatting library. It can be used as a safe alternative to printf or as a fast alternative to C++ IOStreams.

In Topic: Drawing Crosshair in perspective?

22 May 2016 - 09:17 PM

Is there some reason you need to use the same camera to draw the crosshair? Generally it's much simpler to use a separate camera to draw HUD elements.

In Topic: c++: sprintf but return chars. Possible?

22 May 2016 - 02:18 PM

void doStuff(const char*);

int main()
    int myInt = 555;
    std::ostringstream ss;
    ss << "Mytext: " << myInt;

In Topic: HLSL (MonoGame) Trying to set pixels to avg color of a non-square block

18 May 2016 - 08:02 PM

You're asking for help for a shader algorithm, but you haven't posted any shader code.


You showed the C# code to do this on the CPU, but it's unfinished (you don't do anything with "newColor") - and yet somehow you have a screenshot of the results of this for use as a reference image of the working version (presumably this is what "Me doing the average calculation" is - though it certainly doesn't look like it's averaging out colors - it looks like some dither pattern).


I'm just confused. And probably other people are too, hence the lack of replies.



You're trying to create a (width / 16) X (height / 8) size image where each pixel is the average of a 16x8 block of pixels of the original image - is that correct?


- You could accomplish this by rendering smaller versions of the original scene, but you'll need to go in steps of 2, since a bilinear filtering operation is only sampling from neighboring pixels (i.e. if you sample exactly from the corner of 4 pixels, you'll get a result that is the average of that 2x2 square) . So you'd need to go from say, 16x8 to 8x4 to 4x2 to 2x1 to 1x1.


- You could also have your render target automatically generate mipmaps, but those will be half sizes, so you'll still need to do at least one "resizing" pass to get your rectangular sample area.

In Topic: marking world objects as "currently being used" by players

11 May 2016 - 02:13 PM

>> If your code is flexible enough to support multiple notions of ownership for a game object (visual, inventory, tribe, etc...), then this should just be a matter of a player having a "temp crafting inventory". Those items are placed in the "temp crafting inventory" as needed - then when the player is done crafting, the "temp crafting inventory" is emptied. All along the items remain visible in the world, but any code that checks if someone can pick it up needs to check that it isn't owned by a "temp crafting inventory".


i use the world object's generic data[i] variables to indicate ownership. these are checked when an attempt is made to use the object. but "emptying the crafting inventory", IE the call to stop_using_anvil_stone() - which "un-marks" it - must be called at each bail point in an action handler, as well as the funneling chokepoint at setaction(DONOTHING). i may be able to just put it into setaction(DONOTHING), but i still have to hanlde it for all oversized objects, or large piles of parts and tools tool big for the player to carry at once.


some games exhibit systems like this, such as the sims with fridges, and skyrim with smithing tools like grindstones and forges. "someone else is using this".


i suppose they too use "in use" flags and owner and/or ownee pointers / IDs, which must be both set and cleared.




Ideally you want this:

- a single place where the "items in use" for an actor is emptied.

- a single piece of state that associates the item with an actor's crafting inventory


The fact that you claim you need to do cleanup at multiple bail points in your action handler suggests a design problem. There should be a single place where an action is stopped/deinitialized/whatever, and your crafting action can empty its "items in use".


setAction(DONOTHING) is not that place, except that it should stop/deinitialize any previously executing action, which - in the case of the crafting action - the crafting action will then empty its "items in use".



If you only have a single piece of state that associates the item with an actor's crafting inventory, then cleanup is not a problem. Consider: if that piece of state is simply a list of "items in use" (associated with each actor), then when you empty the list in your (single point of exit) crafting action cleanup, you're done. Nothing left to do. Your entire cleanup code that needs to ensure all state is consistent and all loose ends are tied can simply be "list.clear()".



Of course, the code that lets an actor grab an item now needs to be able to query all actors' "items in use" lists to ensure that an item is available for the taking. If this becomes a performance issue, then you can start tackling that as a performance issue (by perhaps querying only nearly actors as Sean suggested, or by having "weak state" on an item that indicates the last actor that used it).