Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 18 Mar 2013
Offline Last Active Yesterday, 07:14 PM

#5314367 supplying character spritesheet

Posted by on 08 October 2016 - 05:18 PM

Check out Spriter or Spine


With spriter you can export good ol fashion spritesheets but save your projects so that you can easily switch clothing and animate your sprites within Spriter.


Spine has c API that will let you use the Spine animation data directly - this is a bit more involved/advanced but results in smoother animations. Last time I checked Spriter only had a library written to use this data with SFML.


In any case you can just export spritesheets and use the program to do your animation stuff. Saves a lot of time.

#5307079 Name this causal game

Posted by on 21 August 2016 - 04:25 PM

Dotty McDotface

#5306931 What's a room?

Posted by on 20 August 2016 - 07:07 PM

What is a space? It's just a collection of game objects and related geospatial systems. A space contains a physics world. A space contains a scene graph. A space would contain data like AI maps. A space contains a set of entities.


So - what exactly distinguishes a "space" from just a "scene"? If all of your systems, for example, only operate on things in a scene that you pass in as a parameter to the system's work functions?


I have sort of run in to this issue lately - but it seems like using "scenes" works the same as spaces, where all entities contain an id indicating which scene they are in and they cannot actively be in more than one at a time - but they actually live in memory in some higher world object.

#5306635 Some problems with ECS design

Posted by on 18 August 2016 - 05:14 PM

Very well. But... I am designing abstract ECS library that can be used everywhere. 



I know it sounds great - but just to warn you - be prepared to waste a lot of time without ever having anything practical.



I really do not understand how can I get entities with specific components without performance issue. If I add some "glue-components" like this:



When you iterate though components of a given type in a system, you will likely be able to get the entity with

entity * ent = cur_comp->owner() or something. Then get the id to the comp you want:

uint32_t other_comp_type_id = 1234;
uint32_t comp_index = ent->get_component(other_comp_type_id);
compont_type * other_comp = &world->get_comp_array(other_comp_type_id)[comp_index];

Then in your get_component in the entity something like

uint32_t entity::get_component(uint32_t comp_type)
    auto fiter = m_comp_umap.find(comp_type);
    if (fiter != m_comp_umap.end())
        return fiter->second;
    return -1; // indicates no component

Yes a hash map would be plenty fast enough. Sorry about no code tags - my browser at work doesn't show them (even after pressing more reply options).


You really should try to make a game instead - even if your ultimate goal is an engine. How could you possibly write code that is to be used without writing, or at least having, the usage code? 

#5306563 Some problems with ECS design

Posted by on 18 August 2016 - 10:25 AM

Cashe friendly hash map : google::dense_hash_map

You can either use indices in to the vectors, or you can use direct pointers if you can gaurentee the component vectors stay below some capacity that you set at startup.

If your using vectors to store you comps, and are using the indice method, you have to make sure your comps are still valid when copied.

A dense hash map with comp type id to comp index per entity would perform just fine.

#5306390 Is The "entity" Of Ecs Really Necessary?

Posted by on 17 August 2016 - 12:59 PM

Im not sure i follow the systems are God class argument - it seems pretty clear that systems should deal with one aspect of game logic - so that the logic is encapsulated within the system. I guess they are God classes in the sense that they know about multiple game objects.

With systems responsible for specif portions of game logic, components can then be used as a method for intersystem communication without having to use messaging - so that no system is dependent on another system (though i usually end up having intersystem dependencies of some sort anyway - but they are well defined meaning a the game wont compile if a system isnt there that another system needs). If game objects dont have some component needed by a system to execute logic then the system does not process that game object - or it acts in some well defined way (such as no material component then use a default material that makes it obvious that a material is missing)

The only logic within components is logic pertaining to itself - this could be setting a needs processing flag for example on changing a component value - this separation is really just syntactic sugar

I dont have the actual component data live within systems - my components essentially live within the entities for all intents and purposes of API. Internally they live in component type specific arrays and the entities keep indices in to these arrays - and systems have access to these arrays so they can loop through and process them, but adding and removing components is only done through the entities' interface.

Creating a new component type is then a separate operation from creating a new system, but often they do coincide. The granularity is left up to the user - you could theoretically create a single system that processes all components - a true "God class" - but thats not what it is meant for.

Systems are updated in a well defined but customizable order, with as many or as few as needed to make the code both work and remain maintainable.

I just dont see a clean way to have global state without "systems", and you definitely need global state. If not systems then either your game object components need to know about eachother, or you have to have some kind of objects in place with the larger game state that the components have access to. It seems like you would then need to worry about the order that game objects are updated, or loop through the objects multiple times calling different functions each time - which is essentially what systems are doing in a nutshell.

Maybe doing that is clean and fine - i did things that way at first following the unity model - i didnt like it and found myself frequently getting confused on how exactly i should implement game logic that required inputs from many game objects at once.

At the end of the day though i guess its just a matter of preference which one way to do things is "better".

#5305132 Is The "entity" Of Ecs Really Necessary?

Posted by on 10 August 2016 - 10:25 AM

If the compnents arent associated in some way, how would you know which transform component to get the position from when rendering the mesh component (or render component or whatever it may be called)

Either you would need to combine EVERYTHING needed to perform some action within a system in the component that system operates on, or store a list of components within the component to see which ones are associated, or use a common id between related components (and so the entity id is born)

For example - many systems will probably need the position information for things in the game in order to do anything useful - would you store a copy of this in each component? If so, then why have "components" at all?

#5304033 A Lightweight 2D Game Framework Doesn't Seem To Exist

Posted by on 04 August 2016 - 11:59 AM

I like your idea but i dont like the "managed memory with smart pointers". I mean - do whatever you want to do internally but please let me have just a good old fashioned pointer when i want one.

Though this may cost me some down-votage - I dont care - I think the std smart pointers are way overrated.

I also dont like Unity, it feels less like coding and more like web design or something to me. Yeah, you can definitely make 2d platformer games with it faster than anything else - but there is definitely a crowd of us still in the world who enjoy coding at a lower level.

The question is though, since this would seem to be more of your target audience for such a library, why would we rather use your lib than something like sdl or sfml?

I think the answer to this question is probably why there arent too many options out there.

However, i could definitely see it being useful for us when we are looking to pump out a game very quickly (for a week game contest for example) and dont want to open the Unity box. It better be transparent and well documented though!

#5303710 Only 12 Enemies, And My Fps Drops To 30, Why Is That?

Posted by on 02 August 2016 - 02:40 PM

For your profiler question - the one that comes with vs community 2015 is great if your on windows. When i build on windows its what I use.

When building in linux i use Qt creator debugger along with its included valgrind profiler.

Both of these are free to use for open source projects.

#5303533 Ecs Inheritance Problem (C++)

Posted by on 01 August 2016 - 01:26 PM

I don't see any reason for making your component a templated type - why not just loose the template?

struct component
    virtual int GetType() = 0;

struct positioncomp : public component

	static const int TypeID = 1;


	int GetType() { return TypeID;};

	int x;
	int y;
	int z;


As for storing this - in your entity you would have something like

struct entity
    std::map<int, component*> ent_comps;

And then, somewhere else you would store your actual type specific components in their own vectors/arrays. This vector could be in the system that uses them, or somewhere else but preferably not global. I store my type specific vectors in the same object where I store my entities - like so. EDIT*see end of post about why it can be bad to store pointers to data contained in vectors as the above entity would*

struct entities_data
    std::vector<entity> loaded_ents;
    std::vector<positioncomp> position_comps;

This has the disadvantage that for every new type of component you create, you need to edit the entities_data struct. However, you can do some template-ish types of things to make it so that you don't have to, but it makes things confusing and isn't really necessary unless your building some library that lots of others will be using I suppose.. You could do something like this...

struct comp_container


template<class T>
struct comp_container_concrete : public comp_container
    std::vector<T> loaded_comps;

struct entities_data
    std::vector<entity> loaded_ents;
    std::map<uint32, comp_container*> loaded_comps;

template<class T>
bool register_comp_type(uint32 type_id, entities_data * edat)
    auto f_iter = edat->loaded_comps.find(type_id);
    if (f_iter != edat->loaded_comps.end()) // comp type already registered
        return false;
    return edat->loaded_comps.emplace(new comp_container_concrete<T>).second;

Anytime you are using a vector to store the actual data, make sure that the data is copy-able or else your data will likely become corrupt any time the vector needs to allocate more memory (ie the size exceeds the capacity).


Also, you won't want to distribute pointers to elements in the vector because they can become dangling when vector reallocates - instead I would use an index in to the vector. Another option if you really want to use direct pointers is to pre-allocate the vector (set the capacity), or just use a static sized array. If you use indexes in to the vector rather than pointers, when an element is added or removed from the vector you will need to update the indexes used by your entities accordingly. Your entity in this case would be:

struct entity
    std::map<int, int> ent_comps;

where the first index is the comp type, and the second is the index in to the comp vector.

#5302939 I Can't Properly Rotate The Enemy To Look At Me All The Time.

Posted by on 28 July 2016 - 09:06 AM

I think your solution is fine but it might be worth it for you to switch over to quats in the future as they can make life a lot easier especially if you start animating things..

It seems glm has them already built in with gtx namespace?


#5302769 2.5D Movement Problem

Posted by on 27 July 2016 - 11:32 AM

I believe double dragon is done with orthographic - and most of those type of games - if you do perspective rendering i still think you should only persepctive tform for rendering meaning moving forward and back would go along the projection lines - otherwise it will seem like your moving diagonally

That being said - you could simply render your characters with an orthogonal projection and everything else with perspective - but i think its going to have a strange feel.

In any case i wouldnt involve the projection for EDIT*anything but* rendering in your world positions

#5300230 Object not rotating as it should

Posted by on 11 July 2016 - 12:48 PM

From the code provided it is impossible to tell how you are multiplying your matrices as you call a function to do the multiplication and i have no idea how that function is doing the multiplications

In general, using glsl standards, your tform would look something like

mat4 finalTform = projMat * camMat * objTranslateMat * objRotateMat * objScaleMat

And if you wanted to rotate around some point other than the origin - you add that to the lineup as a parent transform

mat4 finalTform = projMat * camMat * parentTform * objTranslateMat * objRotateMat * objScaleMat

And your parent tform can be its own combination of scale, rotation, and translation matrices. Leaving you with

mat4 finalTform = projMat * camMat * parentTranslateMat * parentRotationMat * parentScalingMat * objTranslateMat * objRotateMat * objScaleMat

To move the object relative to the rotation pivot point you would edit the position used to build the objTranslate mat, to edit the rotation around this point you would edit the parentRotationMat, to edit the world position of the rotation pivot point you would edit the parentTranslateMat, and to edit the local rotation of the object you would edit objRotationMat.

In your case you seem to only be interested in moving the rotation pivot point which means you could drop everythinh else leaving

mat4 finalTform = projMat * camMat * parentRotationMat * objTranslateMat

Note that changing objTranslateMat will move your pivot point around

#5299675 How to implement wave equation?

Posted by on 07 July 2016 - 02:37 PM

A lot of things could be wrong here - including compile/link errors with the shaders - if not then likely your equations are producing huge delta values.


I would start with a simple traveling wave in a single direction - assuming your water is in x y plane then just vary z according to time and either x/y - expand from there.


new_z = position.z * A * sin( 2 * pi * f * time - beta * position.x) // varying according to x


where A is the amplitude, f is the frequency in hertz, and beta is 2 * pi * f / phase_velocity. Most emag wave equations would assume a phase velocity of the speed of light, but I would chose a more sane and visible phase velocity.


If you want the wave to travel across your water in the x direction at 1 unit per second for example and you want the wave to complete an up/down cycle once per second: f = 1, beta = 2 * pi * f / phase_velocity = 2 * pi 


which lands you at


new_z = position.z * A * sin(2 * pi * (time - position.x) )


You could adjust A, starting very small, until you see noticeable waves going in the x direction across the water. Start adding to get to the other wave equations from there.

#5298123 General questions about game engines and frameworks

Posted by on 26 June 2016 - 11:35 AM

OpenGL and DirectX are low level APIs that give you indirect access to the GPU and allow you to draw things to the screen using hardware.


SFML has 5 modules: system, window, audio, networking, and graphics. The graphics module uses OpenGL to draw things, and the window module creates an OpenGL context. The other 3 modules, as far as I know, do not use OpenGL.


So to answer the second part of your question - SFML and SDL are not substitutes for OpenGL/DirectX - they do provide a set of functions/classes that wrap OpenGL to try to make it a bit easier to use. You can, with both SFML and SDL, use your own OpenGL code in conjunction with theirs and their documentation shows exactly how to do this.


You cannot use Direct3D with SFML/SDL - though you could probably use it with SFML if you only use the audio, networking, and system modules.


EDIT: Also - SFML is a good framework to use if your wanting to learn to build your own engine in my opinion. It will take care of a lot of details to get you up and running - and as you learn you can disable modules replacing them with your own code if you would like - or with other libraries specific for the task at hand. For example - you could start with having SFML load your images from file, then later change that out with stb_image or devIL if you like.