• 13
• 27
• 9
• 9
• 20
• ### Similar Content

• I have a native iOS game (objective c, XCode build) which I am considering to port to other platforms.
Core gameplay is based on solely on geographical maps, and custom drawing over maps. It also has Core Data. This part is complete in development.
What is not done yet is: monetization, gamification (leaderboards, challenges) and multiplayer functionality.
As I think more about it, I am tempted to think if this is the right time to move to a cross platform tool such as Unity. But before dedicating time to port my 5 years side-project effort in Objective C, I really want to know if its worth it.
- Does Unity support such plugins / assets that will fulfill all my above requirements?
- Unity Personal seems to have only 20 concurrent users - is it too costly scaling if I decide for extending to web and android platforms?
- What is the general workflow involved in publishing to iOS, Android, PC, and web platforms while using Unity? I mean to ask about various points of signing stuff, paying fees and getting certified.
- How long will it really take to port my entire Objective C project into Unity? I am somewhat familiar with C# but I am finding it hard fidgeting with Unity IDE as lot of things are focused around FPS and 3D while my game is still 2d - not much action involved. I seem bit overwhelmed by the list of features I see there. All in all, I do not want to lose my momentum while still making sure its portable to everywhere.
- Any assets I could use (for free to try basis in debug) that are relevant for my game?
- Last but not the least, are there any costs that I need to be paying upfront to Unity, for using it (apart from their monthly subscription model)? I don't understand their costing for multiplayer in conjunction with their subscription fees - if someone could kindly elaborate.

• Hi everyone, as summer approaches and the college semester comes close to ending. I want some books or resources you would reccomend to a beginner video game programmer.

On a side note, what are the important calculus topics that are applied to programming video games?

• By FFA702
I've been working on a small 3D game maker app for a while, but it's now shaping up to be a full fledged (albeit simple) all integrated 3d engine. I think it's promising in the sense that I've built the App I would want to use, and I can see people (mainly beginners) using it for a lot of applications. It has no name yet. I don't plan on making it open source or selling it. I'm just considering setting up a small website with some documentation and a download link.
What kind of license would I join with the tool given that:
I want people to be able to use it freely
I want to be completely free of responsibility
I want to prevent people from removing, let's say (hypothetically, not sure how I'd go about this yet), a small banner advertising my software at startup from the application the software would produce
The tool was developed in visual studio community 2017, using C# and a single external library, openTK
Is there anything else I should think about ? Perhaps when naming it ?
EDIT: Also, what about, let's say, a logo, or a design pattern (Artistically speaking) I would use throughout the program and the documentation to make it easily recognizable. How would I go about protecting that ?
Thanks guys
• By Orella
I'm having problems rotating GameObjects in my engine. I'm trying to rotate in 2 ways.
I'm using MathGeoLib to calculate maths in the engine.
First way: Rotates correctly around axis but if I want to rotate back, if I don't do it following the inverse order then rotation doesn't work properly.
e.g:
Rotate X axis 50 degrees, Rotate Y axis 30 degrees -> Rotate Y axis -50 degrees, Rotate X axis -30 degrees. Works.
Rotate X axis 50 degrees, Rotate Y axis 30 degrees -> Rotate X axis -50 degrees, Rotate Y axis -30 degrees. Doesn't.

Code:
void ComponentTransform::SetRotation(float3 euler_rotation) { float3 diff = euler_rotation - editor_rotation; editor_rotation = euler_rotation; math::Quat mod = math::Quat::FromEulerXYZ(diff.x * DEGTORAD, diff.y * DEGTORAD, diff.z * DEGTORAD); quat_rotation = quat_rotation * mod; UpdateMatrix();  } Second way: Starts rotating good around axis but after rotating some times, then it stops to rotate correctly around axis, but if I rotate it back regardless of the rotation order it works, not like the first way.

Code:
void ComponentTransform::SetRotation(float3 euler_rotation) { editor_rotation = euler_rotation; quat_rotation = math::Quat::FromEulerXYZ(euler_rotation.x * DEGTORAD, euler_rotation.y * DEGTORAD, euler_rotation.z * DEGTORAD); UpdateMatrix();  }
Rest of code:
#define DEGTORAD 0.0174532925199432957f void ComponentTransform::UpdateMatrix() { if (!this->GetGameObject()->IsParent()) { //Get parent transform component ComponentTransform* parent_transform = (ComponentTransform*)this->GetGameObject()->GetParent()->GetComponent(Component::CompTransform); //Create matrix from position, rotation(quaternion) and scale transform_matrix = math::float4x4::FromTRS(position, quat_rotation, scale); //Multiply the object transform by parent transform transform_matrix = parent_transform->transform_matrix * transform_matrix; //If object have childs, call this function in childs objects for (std::list<GameObject*>::iterator it = this->GetGameObject()->childs.begin(); it != this->GetGameObject()->childs.end(); it++) { ComponentTransform* child_transform = (ComponentTransform*)(*it)->GetComponent(Component::CompTransform); child_transform->UpdateMatrix(); } } else { //Create matrix from position, rotation(quaternion) and scale transform_matrix = math::float4x4::FromTRS(position, quat_rotation, scale); //If object have childs, call this function in childs objects for (std::list<GameObject*>::iterator it = this->GetGameObject()->childs.begin(); it != this->GetGameObject()->childs.end(); it++) { ComponentTransform* child_transform = (ComponentTransform*)(*it)->GetComponent(Component::CompTransform); child_transform->UpdateMatrix(); } } } MathGeoLib: Quat MUST_USE_RESULT Quat::FromEulerXYZ(float x, float y, float z) { return (Quat::RotateX(x) * Quat::RotateY(y) * Quat::RotateZ(z)).Normalized(); } Quat MUST_USE_RESULT Quat::RotateX(float angle) { return Quat(float3(1,0,0), angle); } Quat MUST_USE_RESULT Quat::RotateY(float angle) { return Quat(float3(0,1,0), angle); } Quat MUST_USE_RESULT Quat::RotateZ(float angle) { return Quat(float3(0,0,1), angle); } Quat(const float3 &rotationAxis, float rotationAngleRadians) { SetFromAxisAngle(rotationAxis, rotationAngleRadians); } void Quat::SetFromAxisAngle(const float3 &axis, float angle) { assume1(axis.IsNormalized(), axis); assume1(MATH_NS::IsFinite(angle), angle); float sinz, cosz; SinCos(angle*0.5f, sinz, cosz); x = axis.x * sinz; y = axis.y * sinz; z = axis.z * sinz; w = cosz; } Any help?
Thanks.

• Hi there,

Thinking about improving strategy/survival web/app based game with some action in it. Because leveling up the infrastructure, gathering resources, etc, is getting bored. To be more specific it's a survival game, based on astronomy, trying to save planet, etc.
So the "fighting" model doesn't fit here, because there are no dragons on the planets :))) Either its a co-op based, so PvP also doesn't fit.
Thinking about some puzzles solving at some point of game or turn-based/event-based dissasters handling... Stuck there
What do you think ?

# C++ Guidelines for determining what should be a component

## Recommended Posts

Background:

So I'm developing my first 2d C++ fighting game (for learning purposes) and I have a setup where I have 'components' which are really just data holders with maybe some simple utility functions such as GetComp(), AddToComp(), etc. All components get passed to component systems which are just functions which act on certain components (e.g. MovementSystem(PositionComp pos, VelocityComp vel), etc.) which are split up into their respective domains (Graphics, Animation, Physics, etc.). All components are held by 'Fighter' class which acts as the component holder that keeps everything together.

Issue:

The problem I'm having is I'm not sure how I decide what exactly should be made into a component vs what shouldn't. For example, for my animations I have a system which essentially takes a 'spriteComponent' and a 'animationClip' obj like so SetAnimation(spriteComponent sprite, animationClip anim). As it stands, my animationClip class is not considered a component and is not currently attached within my Fighter class, though I guess I could implement it that way. How do I decide what classes/types should be made into components? How is this typically handled in other ECS (entity component) like systems?

##### Share on other sites

I'd default to making as few things components as possible, and prefer passing parameters to the components.

Think of it like this - what does a visual system need from its component to function properly? If nearly every visible entity requires an animation, then the entities that have that visual component should have the animation passed into that component. (I'm using "visual" as a concept, not a system name).

Anything that can be parameterized probably should be, though I'm sure I could think of exceptions. Most programmers recognize that Composition is more often preferred over Inheritance. I think when it comes to Entity Component Systems (ECS), composition and parameterization of components is more often preferred over more components.

Don't forget that you can make some components depend on the existence and data of other components - pass in a reference or ID as a parameter.

Why, for example, are Position and Velocity part of two different components? It's like separating every variable of a class into its own component - but for what benefit? Even walls can have velocities - just set the velocity to (0,0). And what about size and collision rects? I'd have them as part of the same component. If an object doesn't collide, for example, I'd just set a bool or set the collision rect to (0,0,0,0).

Think of components as structs, not solo variables. They are bundles of variables needed for the System to do its thing. Sometimes a system needs the data separated in more than one component, but they shouldn't be unless actual concrete benefit is gained by their separation (and theoretical future benefit doesn't cut it).

I'm not familiar with your particular code, but another thing that seems odd is that there is a Graphics system and an Animation system. What does the Animation system do?

##### Share on other sites

Thanks for the reply. I think this:

Quote

Think of components as structs, not solo variables. They are bundles of variables needed for the System to do its thing. Sometimes a system needs the data separated in more than one component, but they shouldn't be unless actual concrete benefit is gained by their separation (and theoretical future benefit doesn't cut it).

really hit the nail on the head. I'm kinda like you where I've read up on ECS systems and game engines but again this is my first time trying to implement these things into an actual project.

Right now my animation system really isn't doing a whole lot lol. I know that, from what I've read, animation and graphics are usually very tightly coupled but I would still see them implemented as 'separate' systems in some code samples so that's why I'm starting out with two separate systems. It helps me reason about things better while I'm learning. Basically my animation system is just setting an index from a 'spritesheet' texture to a spritesheet component. The spritesheet comp holds the texture's current UV coordinates and has a SetUV function which set's the UV coords for whichever index is specified. In the graphics system I then just check that spritesheet component's current UVs set and renders the image found at those coords. More refactoring required but a good start for me :->

##### Share on other sites

These are slightly off-topic from what you are currently reasoning over, but I've written some of my thoughts on common ECS design pitfalls here and here, and you may find them worth a read. I haven't mentally resolved every aspect of how I would design an ECS, but I've come to a few conclusions about how I wouldn't design them, basically by observing what I think others do wrong. Again, I should stress that I'm no expert, I just play one on TV.

##### Share on other sites

ECS is a design pattern, and like any other pattern, you should not (ab)use patterns to "design by numbers". Patterns are not a play-book, they're a vocabulary so that it's easier for us to communicate with each other.

Questions like this boil down to: I've picked a pattern to use as my solution, but I'm not sure how to fit my problem into it.

Also, Entity Component Systems are not really a recognized design pattern outside of games... and it's not even popular within games. IMHO it's just an ad-hoc reinvention of the relational model.

To answer the question though: If you're using ECS, then everything is a component.

If you're using OOP, the guideline on when to break an object into two is called SRP.

##### Share on other sites
10 hours ago, Servant of the Lord said:

Why, for example, are Position and Velocity part of two different components? It's like separating every variable of a class into it's own component - but for what benefit? Even walls can have velocities - just set the velocity to (0,0). And what about size and collision rects? I'd have them as part of the same component. If an object doesn't collide, for example, I'd just set a bool or set the collision rect to (0,0,0,0).

Finding the right degree of separation is not a simple task, as you have laid out. If you have Position, Scale, Rotation, Velocity, MoveSpeed, Collision, Size, ... as components, you end up having to add a fuckton of components to a single entity, to even make it work. On the other hand, if you end up merging too many responsbilities into components, you lose every benefit that ECS even has.

I personally strife for a middle ground - for example, there's a Transform componen that consists of position/scale/translation, and supports inheriting it from parent entities. Velocity isn't part of this component though, as it doesn't make sense for me - just as little sense as a "velocity" component - instead there are dedicated components that deal with velocity, ie. a Move-component, which contains configuration variables (move-speed, play animation while  moving, ...) but also deals with the velocity part; while on the other hand there could be a "physics" component which applies a velocity on its own.

Thats probably my conclusion - do not strife for declarative components like "position" or "velocity", but instead for functional ones like "Transform" and "Movement", and strife to do othe rest via variables; this should give a decent compromise.

##### Share on other sites

@Juliean Fantastic, that helps a lot. This seems to be inline with what @Servant of the Lord was getting to as well, which was to not make components too granular.

##### Share on other sites

@Juliean Let me ask you though, how do these kinds of systems usually allow users of the engine (typically implementing the game logic layer) to access and set the values of the component variables? Are users typically given knowledge of this underlying engine component or do they typically manipulate these values indirectly via the containing entity class member functions or some other mechanism?

##### Share on other sites
7 minutes ago, boagz57 said:

Let me ask you though, how do these kinds of systems usually allow users of the engine (typically implementing the game logic layer) to access and set the values of the component variables? Are users typically given knowledge of this underlying engine component or do they typically manipulate these values indirectly via the containing entity class member functions or some other mechanism?

If you want to set the values of the components, then you should generally do this directly on the components, yeah. Like that:

auto& move = entity.GetComponent<Move>();
move.speed = 100.0;

For more complex operations you can eigther give the components methods, or add those to the systems and let the user access & call them as well. I'm doing this ie. for my move-commands:

void MoveSystem::MoveTo(Entity& entity, Vector3 vLocation)
{
auto& move = entity.GetComponent<Move>();
auto& transform = entity.GetComponent<Transform>();

// ...
}

Those actually take an entity, but you could also just pass the components - I cannot give a clear advice on that, since I actually use a visual-scripting system for gameplay-logic, which has a specific set of requirements. For example, components do not exist as distinct types here, and I just add a "SetEntityMoveSpeed(entity, speed)" node to achieve the code above. Which might go against what I originally suggested, but its really just of how my system works.
Thats another general advice that I can give, see what works for your case, based on real-life observations. Something that might theoretically be the better/cleaner design might be a pain in the ass to work with, especially on a game-logic level.

##### Share on other sites
Quote

If you want to set the values of the components, then you should generally do this directly on the components, yeah. Like that:

Haha, this is exactly how I was feeling when you were describing just manipulating components directly "yeah.....no?" Obviously because ever since you start programming your always taught to encapsulate and data hide and all that. But I think your final sentence explains it all

19 minutes ago, Juliean said:

Something that might theoretically be the better/cleaner design might be a pain in the ass to work with, especially on a game-logic level.

Sometimes the cost of bending/breaking the rules a bit is far less then adhering to them. Maybe this would be one of them given components are really theoretically just data containers and high level code is easier to deal with.

Though I will say then when it comes to my systems I like the idea of trying to implement no side effects by either just taking copies of components within systems and returning new components or taking const references and just pulling out the data I need from the components and again returning a new component.

Edited by boagz57