Jump to content

  • Log In with Google      Sign In   
  • Create Account

noizex

Member Since 04 Jul 2011
Online Last Active Today, 02:18 AM

#5127752 Indie game - Town of Salem

Posted by noizex on 31 January 2014 - 09:41 AM

Reminds me of Salem (http://www.salemthegame.com/) /in art department of course/ You guys were inspired by that game or came with that art style yourself? It's weird how this look fits into "salem" theme somehow, and I can't exactly say why :)




#5081666 Game state management (C++)

Posted by noizex on 30 July 2013 - 05:48 AM

Hard to tell because you provided only partial pseudo-code for your solution. The usual way (I think) it is done is - you don't instantly change the state (especially not as a responsibility of state class itself), but you ask to change the state on next update. Then finite state machine gets updated and it processes to next state, cleaning up old one. It does not require holding any copy or anything like that. Its just: finish old state, prepare new state, switch current state to new state.




#5042718 Game entity/component system - creation argument list

Posted by noizex on 13 March 2013 - 09:01 AM

Thanks for all the answers!

 

If you can use C++11, you could use variadic templates and std::forward your arguments to constructor. If you can't you can still template arguments, though it will be a bit more work (you have to define templates for all possible numbers of arguments, or use some macro magic - with variadic templates its just one line of code).

 

The varidic templates definitily sounded interesting, but unfortunately they are not supported by Visual Studio 2012... If I were to write templates for all the possible number of arguments given, would I also need to overload the function for each of these templates (Arguments1<>, Arguments2<>, ...) or is there some way to templatize (is this a word) the templates so that I can have "Component::Component(Arguments args)" for me to pass as many arguments as I want?

 

About MSVC2012 - it supports variadic templates and few more C++11 features when you install CTP_Nov2012 (http://www.microsoft.com/en-us/download/details.aspx?id=35515) toolset and set it in your project options. Its CTP so its for testing but I use it and it works without problems. IMO having variadic templates is worth it smile.png

 

If you want to pass it around with varied number of arguments, that will be hell lot of templating. I was thinking about making a component factory with varied number of arguments that are then passed to constructor, and this factory gives you component. Something like:

 

Component* comp = compFactory->CreateComponent(SPATIAL, arg1, arg2);
Component* comp = compFactory->CreateComponent(RENDERABLE, arg1);
Component* comp = compFactory->CreateComponent(COLLIDABLE, arg1, arg2, arg3); 

 

Above code could be achieved by templating factory function "CreateComponent" to support different numbers of arguments that are passed to constructor, but as I said without variadics its a bit of crazy template magic (check this article and source code for really nice factory implementation: http://archive.gamedev.net/archive/reference/articles/article2097.html)

 

This can happen on higher level than entity, in some class that creates entities out of components. Does entity really need to know how to construct components (and itself?) or it should be responsibility of class above entity, that picks needed components (probably out of templates later, so its more automated) and creates another instance of entity by attaching necessary components. In some Entity System implementations, there is no such thing as Entity class, but its just a tag or id under which certain components are glued together by some "EntitySystem/Manager". 

 

In my implementation, I kept GameObject class but its only responsibility is to be a container of component pointers that also keeps a bitmask of what component types are attached to that entity (I use it as for very fast lookups, as such bitmask works like a key that you can latet bit-and against some mask of required components and quickly filter entites that meet these criteria).




#5042672 Game entity/component system - creation argument list

Posted by noizex on 13 March 2013 - 06:13 AM

If you can use C++11, you could use variadic templates and std::forward your arguments to constructor. If you can't you can still template arguments, though it will be a bit more work (you have to define templates for all possible numbers of arguments, or use some macro magic - with variadic templates its just one line of code).

 

And I don't think there is anything wrong with constructing component object outside and attaching it to entity - you may want to do some sort of pre-processing and set various information so why not do it this way? As long as you have clear state of ownership of such component it won't be a problem. 




#5041742 Best Practice for Values Return C/C++

Posted by noizex on 11 March 2013 - 01:57 AM

This is a bit off-topic, as the OP didn't ask about error handling but how to return from a function - but I wanted to address maxgpgpu arguments concerning error-handling. It seems nice at first, but when you start wondering about it - is there really a reason to return several errors when initializing and setting data to your VBO? Or when reading from terrain data volume to create a terrain mesh? Or when loading a texture? In all these cases, if the game is going to run properly it _has_ to succeed.

 

If you can't load texture, load default texture thats guaranteed to be loaded (or application won't start). If shader is missing - return some default shader and log error (plus this should be of course fixed for the release, because missing textures and shaders are no good). If you can't initialize VBO, something is very wrong and your application either has flaws that lead to this or its exceptional behaviour and should just result in exception thrown. 

 

What I'm trying to say is that if your code is error-driven you will spend a lot of time returning various error codes from nested functions and having to handle them. What I found way more useful is to code in a way that errors basically don't occur (as an expected result) or are very rare. Use assert() and logging in debug mode to catch possible fatal errors that result from invalid program state and fix them so they do not happen, or are handled as they should. For something that can always happen but is exceptional throw exceptions. In rare cases you may need some multiple-value error code, but I looked through my app and I can't see anything like this (I don't count functions that don't return any other result than bool for success/failure).




#5041445 Best Practice for Values Return C/C++

Posted by noizex on 10 March 2013 - 03:37 AM

I agree with Stroppy and Lightness - returning the value that is expected result of a function (instead of some error) is the way to go. Returning error codes is one of most counterintuitive ways for dealing with things. 

 

Of course it all depends on the case - in your case you just want to return Texture so go with your first suggestion, like:

std::shared_ptr<Texture> texture = textureCache.GetTexture("...");

 

I can hardly think of situation that would justify what was suggested above about using return value only for error code (and returning objects by assigning to reference). First of all, its quite hard to determine quickly what happens because you may have references that have different meaning: in, out, in/out. There is no special syntax to indicate it so you have to write a description. If you really need several error codes (which is IMO very rare and if you write code that requires it very often, something is wrong.. - there are cases where such coding is probably only way to achieve something, but I doubt that your case belongs there). 

 

If you REALLY need to use this approach, at least:

  • Make sure your references already tell your intentions, so if you're using reference as "in" only, make it const, if you use it for return value don't make it const:
    int LoadTexture(const string& name, const Type& type, Texture& texture)
    {
        if (load_from_file(name, type))
        {
            texture = <loaded texture>
            return SUCCESS;
        }
        return FAILURE;
    }
    

     

    Here references that are only for reading are marked const, while your return reference is not - its easier to know whats going to happen that way.

  • Or use std::tuple and std::tie to return multiple values from a function (for example std::tuple<Texture*, int> where int is error code)



#5037974 return std::map Question[Solved]!

Posted by noizex on 01 March 2013 - 05:51 AM

Sorry, could you rephrase your problem, because honestly I can't seem to understand what is it about. :) Attached code doesn't make any sense too, try to put here some meaningful testcase.




#5037545 Grass Blocks ( anyway to make them feel more dynamic? )

Posted by noizex on 28 February 2013 - 04:52 AM

So we ran into another problem. The lighting system for our world is deferred rendering, but with such a system you can not have alpha's that work right. We got the alphas to work for the grass but to get the lighting to work on them we had to setup a forward lighting process. In doing so our point lights do not effect them. Any ideas on how we could fix this? If we setup point lights to be forward rendered we limit the number of lights. One of the main reasons for using a deferred rendering method is the thousands of lights we can use. ( which makes for a very nice setting ) I would really hate to have to hinder that based off of the idea of grass being lit.

 

Any unique ideas on how we can bypass this would be GREAT!

 

Are you rendering grass fully alpha-blended? This is not how its usually done (from what I know, and I researched this subject a bit). You want to render grass with one of these methods:

There is some good stuff here on this topic: http://wiki.polycount.com/TransparencyMap




#5037079 Swaying Objects ( non animated )

Posted by noizex on 27 February 2013 - 04:15 AM

Yeah, as someone already mentioned in previous thread, your topics even help refreshing some knowledge and give opportunity to discuss some more "modern" approaches. Searching GameDev does not always yield best and most up-to-date information. smile.png Its just that these 2 papers describe quite well two most widely used techniques, including vertex color, so I felt a bit like stating the obvious and hence asked if you read the papers.




#5037074 Swaying Objects ( non animated )

Posted by noizex on 27 February 2013 - 04:02 AM

Did you try searching for some papers first? There is plenty of information on the web regarding grass/foliage animation and real-time rendering. Most popular ones are probably 2 articles from GPU Gems:

 

http://http.developer.nvidia.com/GPUGems3/gpugems3_ch16.html

http://http.developer.nvidia.com/GPUGems/gpugems_ch07.html

 

+1 for using vertex colors painting method as it gives you most flexibility and is especially good for more complex models (some bushes, trees, weeds and other). But for simple quad based grass you dont have to even paint vertices - as described in mentioned papers (GPUGems Ch07), you need to know upper vertices of a quad to animate them (lower ones touching the ground stay static), and there is very easy method to do this - you use texcoords for it. With default texcoord approach, top vertices have UV's of (0, 1) and (1, 1) so you have to check if texcoord.t >= 0.9 for example. It will be truth for two upper vertices which you can then animate. There is probably a way to optimise this branch somehow, so its for your consideration only. Just wanted to point that for quads its much easier than vertex colors and don't require you to store additional vertex attribute.




#5036055 Grass Blocks ( anyway to make them feel more dynamic? )

Posted by noizex on 24 February 2013 - 05:12 AM

1) Bend the grass quads, and use at least 3-4 of them at different angles/positions. Any modern game seems to use few more quads at different angles so it looks good from any direction. The texture of the grass and how it blends with the terrain is also important, otherwise you have nasty edges and it doesn't look good. This plus some random rotation applied to each blade should give a good result without much work.

 

2) I'm not sure how you generate grass but you can re-generate it once blocks are changed, so you can easily spot which block (that was base for generating grass) disappeared and just don't generate grass there. As you use uniform grid of cubes it will be harder to make a good looking grass distribution - if you used marching cubes mesh, you can easily create a method that will distribute grass over the surface of a "grass triangle", make it conform the normals of terrain, decide, decide on number of grass chunks depending on the size of triangle face etc. I did it and it looked okayish (considering how little time and effort I put into it) also from above, but can't find a picture found a picture!. Its just a single grass billboard distributed quite densely, plus randomly rotated at each position so not a single quad has the same orientation. The terrain is fully diggable so I had the problem of removing the terrain from underneath the grass, but it was easily solved by just rebuilding certain grass chunk taking into account new mesh that didn't have certain grass triangles (but rock for example).

 

savannah.jpg

 

I guess you have it a bit harder because whatever you do, all you have is cubes so distribution will always be tied to these cubes, unless maybe you create some sort of "terrain mask" on which you paint where the grass should appear and apply grass distribution based on this mask, so its not tied to cubes - some engines use such masks to "paint" grass over terrain, but its heightmap, so in case of 3d voxel volume terrain it may not be that easy to achieve.




#5019014 Awesomium Framework, rendering problems C++ and DirectX11!

Posted by noizex on 08 January 2013 - 07:01 AM

The thing that is confusing to me is the src_buffer parameter, I don't understand what kind of buffer I'm supposed to send in. Let's say I have loaded a website into a surface. The site then updates and I need to repaint the texture. How would I use surface->Paint() to do this?

Thanks once again!

Errm. Its not you thats sending data to Paint method, its the internals of Awesomium that do this. You have to define class that has Paint method and receive this data in that method, and use it to initialize/update texture. Its called automatically by Awesomium when it renders WebView, so you dont really need to call Paint yourself. Once you set the factory and load some page in WebView, you call webview->surface() to retrieve that Surface, which should have your page prepared as a texture (or a bitmap data if you use default BitmapSurface).

Check this example: http://wiki.awesomium.com/tutorials/tutorial-1-hello-awesomium.html

You want to do exactly the same but with your own class, that instead of keeping image data in memory, will upload it as a texture to GPU and keep handle to that texture, so you can retrieve it by calling surface->GetTexture() and then use that texture to draw a quad.


#5019008 Awesomium Framework, rendering problems C++ and DirectX11!

Posted by noizex on 08 January 2013 - 06:34 AM

You could probably initialize texture using BitmapSurface data. But best way in 1.7 seems to be creating your own Surface subclass that should provide Paint and Scroll methods. Check this: http://awesomium.com/docs/1_7_rc3/cpp_api/class_awesomium_1_1_surface.html.

Just make your own DXTextureSurface that inherits from Surface class and provide Paint method that would directly update texture whenever its called. It looks like WebCore has a method set_surface_factory that allows you to provide your own factory that will produce DXTextureSurfaces when needed, instead of default BitmapSurface.


Something is up with the website at that link, but the link works. Will check it later when the site works. I was also looking into making my own stuff there, but the problem is that I don't really understand how the functions in the Surface class works. The Paint function is confusing me. I don't understand what it wants as parameters.

Thanks for your help thus far!

 
Sorry, it seems I pasted link with a dot at the end and it borked. This is correct link: http://awesomium.com/docs/1_7_rc3/cpp_api/class_awesomium_1_1_surface.html
 
This is how Paint method should look like:

virtual void Awesomium::Surface::Paint	(	
unsigned char * 	        src_buffer,
int 	                        src_row_span,
const Awesomium::Rect & 	src_rect,
const Awesomium::Rect & 	dest_rect 
)	

 
Whats not clear for you here? Obviously it gives you buffer that contains image data, provides row span information thats also required (you can calculate it yourself having enough info but they give it to you already), format is 32-bit BGRA so you already have all the info to create a texture out of this. The only hard thing here is that it obviously paints only the part that changes, not always re-paints full view, so you have to handle partial updates.
 
Once you have your own Surface class and set its factory, whenever WebView is rendered, it will set up your texture by instancing DXTextureSurface (or whatever you name that class). It will be then available through WebView's method "surface", so whenever you want to draw that WebView you can do something like this (pseudocode):
 

DXTextureSurface* surface = (DXTextureSurface*)mywebview->surface();
DrawTexturedQuad(surface->GetTextureHandle())

Where GetTextureHandle returns whatever you use to identify DirectX's texture (I use OpenGL so can't provide more accurate example here). 




#5018982 Awesomium Framework, rendering problems C++ and DirectX11!

Posted by noizex on 08 January 2013 - 05:03 AM

You could probably initialize texture using BitmapSurface data. But best way in 1.7 seems to be creating your own Surface subclass that should provide Paint and Scroll methods. Check this: http://awesomium.com/docs/1_7_rc3/cpp_api/class_awesomium_1_1_surface.html.

Just make your own DXTextureSurface that inherits from Surface class and provide Paint method that would directly update texture whenever its called. It looks like WebCore has a method set_surface_factory that allows you to provide your own factory that will produce DXTextureSurfaces when needed, instead of default BitmapSurface.


#5017070 Program Wide Global Vars in C++?

Posted by noizex on 03 January 2013 - 06:37 AM

I try to design without globals in mind, but things like debugger/profiler that I have to use and I _need_ access to it from basically every part of my code to dump something on the screen or profile execution just require some kind of global var / singleton (which I don't like and prefer just typical global variable). I tried hard to figure how to pass it around and having it passed through all object chains because I may need it at some point is just plain stupid IMO.

Instead I just create a global instance of Debugger class and in any .cpp file that I need access to it to dump some data or profile part of the code, I use extern. I really can't see how this can be done better - I can't use global functions because I need a state (debug drawing requires geometry to be compiled and drawn each frame etc, so instead of one class I'd have to get some global variables anyway and it will be ugly). Its also only for debugging, so in release mode my code is global free anyway.

I think people who are 100% against globals are some hard to convince OO-freaks.




PARTNERS