C++ :: Game With Entity Component System - Generalizing Repeated Functions

Dec 20, 2014

I'm working on a game with an entity-component system. I have a Manager class that is handling all of the components by feeding them into vectors set up for each type of component. Right now I have a lot of repeated code for each kind of component.

void add_pos_comp(shared_ptr<Position> pos_comp);
shared_ptr<Position> get_pos_comp(int id);
const vector<shared_ptr<Position>>& get_pos_comps();

void add_vel_comp(shared_ptr<Velocity> vel_comp);
shared_ptr<Velocity> get_vel_comp(int id);
const vector<shared_ptr<Velocity>>& get_vel_comps();

I've tried generalizing this with templates, but I've been confused by how I should organize the collection of vectors for each component. I had it setup so that they were all in an unordered_map, but how to get the templated functions to find the right map slot to use based simply on the template's parameters.

The full project is here for reference: [URL] ....

View 2 Replies


ADVERTISEMENT

C++ :: Video Game - How To Set Up Save System

May 20, 2013

I would like to create a video game. It would be text based. How could I set up a save system? Also, how would I load it?

View 3 Replies View Related

C++ :: Writing Plugin Framework / System For Game

Mar 23, 2014

So I'm trying to accomplish something that right seems to hard for it to be worth it. I'm trying to write a plugin framework/system for my game. I have read about it and everything that pops up says it's OS-specific and you have to load the plugins from either a .so file on linux or from a .dll file on Windows. So here lie my questions:

-Is there any universal way of accomplishing this?

-Every way I've seen assumes i know the names of the functions I'm calling which doesn't hold true if the plugin are written by a 3rd party. How would i turn the table on this matter?

View 1 Replies View Related

C++ :: Game Control - Organizational System Giving Errors

Jun 24, 2014

I'm making a game with the following class structure:

GameControl - The class that actually runs the game, with a while(!closed) // run the game loop.

State - A class that handles the state of the game, for example if the game is rendering the scene it would be in one state, and if it is rendering the menu, it would be in another.

ComponentManager - A class that manages all of the components of what is being done, for instance, the Scene class would contain a bunch of components handling the drawing of each tree, physics, the camera, etc. The manager will put them all together.

Component - A component of whatever is being done. A tree (and its rendering code) would be an example of a component of the scene. The camera would be another. The component does not necessarily have to be drawn, it could be handling something like physics (and would throw physics events to other components that need to move in a certain way).

The GameControl class has its loop, which would call the update function on the current State (there are classes that inherit State and override the update function of State).

In the update function of the base class "State", it would take all of the active ComponentManagers and update them. There are classes that inherit the base class ComponentManager and override its update function.

Each ComponentManager would update each of the Components that it owns.

This is the organizational structure that I came up with to make the game scalable and changeable . If, for instance, I wanted to add multiplayer at some point, I would add a class that inherits the State that controls the gameplay called "MultiplayerGameState". This would just add a new ComponentManager that inherits the ComponentManager that controls the player and all of the living things that are moving around. Then, the MultiplayerGameState class would recieve the multiplayer messages coming in and add other player Components for the other players.

My code is giving me various errors like "Forward definition of class State" and "Invalid use of incomplete type State". Unless I made some stupid error that I didn't catch, these are being caused by me including the classes in ways that some of the classes do not see the full definitions of the classes they need to see (because of the preprocessor directives preventing classes from being included multiple times.

Code: (Not implemented exactly as shown above, but I think the main difference is that the main class is not in GameControl, it's in OgreFramework.cpp)

The base classes: [URL] ...
States: [URL] ...
ComponentManagers: [URL] ...
Components: [URL] ...
The project: [URL] ...

My question is: is there a better way to implement my organizational system so that these errors don't occur?

View 1 Replies View Related

C++ :: Simple Game Menu - Program That Simulates Handheld Gaming System

Sep 26, 2013

I have to write a program that simulates a handheld gaming system. a system can have power toggled so its either on or off. when the system is on, its volume level can be raised or lowerd. a system has minimum volume level of zero and a maximum volume level of 10. a system stores games.

// simple game menu
//simulates a handheld gaming system
using namespace std;
class Game {
public:
Game(int GameNumber = 3, int volume = 10);

[Code] .....

View 1 Replies View Related

C++ :: Generalizing Condition In If Statement

Jul 29, 2014

I want to write an if statement which has condition like

if(i%1==0 && i%2==0 && i%3==0 && i%4==0 && i%5==0 &&
i%6==0 && i%7==0 && i%8==0 && i%9==0 && i%10==0 &&
i%11==0 && i%12==0 && i%13==0 && i%14==0 && i%15==0
&& i%16==0 && i%17==0 && i%18==0 && i%19==0 && i%20==0)

This of course is not the right way to write it. How to generalize it so that I can check the condition not only till 20 but till any number without manually adding all conditions.

View 2 Replies View Related

C++ :: Variable Component Names - Calling Checkbox

Oct 17, 2013

I'm trying to find a way to call a variable checkbox.

i.e.

for (i = 10; i < 20; i++) {
Checkbox[i]->Caption = Some Database Information
};

Note: Checkboxes are all called Checkbox10 ~ Checkbox19

View 3 Replies View Related

C++ :: Library (Eigen / Boost) To Calculate Principle Component Analysis (PCA)?

Mar 4, 2013

I have a text file which consists of 907 objects and 1000 feature vector for each object. Is there any Library (Eigen/Boost) to calculate Principle Component Analysis(PCA)?

View 1 Replies View Related

C# :: Data Binding Using Entity Frameworks

Dec 9, 2014

I've got a datagrid setup and i'm using an entity model as the datasource, i thought i had stuctured my query so that i would only get a single column result but the display within the datagrid shows two columns?

here's the xaml for the form

<Window x:Class="UpdateAccelaAssets.winUsersRemove"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Remove User" Height="300" Width="300">

[Code] .....

And I've attached a screenshot of the result.

Attached image(s)

View 3 Replies View Related

C++ :: Function Call That Moves Entity From One Vector To Another

Nov 15, 2014

Ok so I have a function call that moves an Entity from one vector to another, and if one doesn't exist then it creates one and moves it:

std::vector<std::unique_ptr<Entity>> ActiveEntities;
std::vector<std::unique_ptr<Entity>> EntityPool;

// Creates a generic entity in the entity pool
void EntityManager::CreateEntity() {

[Code] .....

In this case it checks the entity pool for an entity, if one exists it moves it to the active entities and then returns the unique id, if one doesn't exist it creates one then calls itself to run the check again to verify and move the new entity.

My question is, is this a valid form of recursion since it only incurs a single loop of recursion, or should I reform the entire system to work differently? If so, how do you set this up in a way that does not cause recursion?

View 3 Replies View Related

C# :: Cascading Deletes In Entity Framework Code First

Apr 15, 2015

I'm a bit unsure on where to put cascading deletes in my models and how far they extend.

I've got four tables

TrafficLog
has a One to One with
TransactionHistory
Has a zero to Many with
OutgoingService
and
Exceptions

Now i'd like to put cascading deletes on, so that if i delete a record from TrafficLog it deletes from the other three.

So do i set up my model with cascade delete just on the primary like this

modelBuilder.Entity<TCC_ArchivedApplicationTrafficLog>()
.HasRequired(TCC_ArchivedTransactionHistory)
.WithRequiredDependent()
.WillCascadeOnDelete(true);

or do i need to enable it on the other three tables too?

View 3 Replies View Related

C# :: Entity Framework - Select Specific Column In Tables

Apr 28, 2015

I need to show in a comboBox thats shows infor from Entity framework but i need to select a specific colum in the tables..

All in C# visual studio xaml form

So I created a var but i get and output: name of programe.NLHEntities

using (var context = new NLHEntities()) {
var blog = context.EtagesChambres
.Where(b => b.TypeChanbre == "Prive")
.FirstOrDefault();
textBox2Type.Text = Convert.ToString(blog);// i put a text box to see what the output would be..
}

View 14 Replies View Related

C Sharp :: Declaring Navigation Property In Entity Framework

Nov 3, 2012

I developed a sample application in EF which has 3 tables

PersonDetails, BankDetails and FixedDepositDetails.

Please find the table structure below

create table PersonDetails
(PersonId int Primary Key,
PersonName varchar(30))  
create table BankDetails
(BankId int Primary Key,
BankName varchar(100),

[Code] ....

But when I run the application I get an error as

The navigation property 'Bank_Id' is not a declared property on type 'FixedDepositDetails'. Verify that it has not been explicitly excluded from the model and that it is a valid navigation property.

If I am not wrong I think I have made some mistakes when creating the model.

View 1 Replies View Related

C# :: Entity Framework Generate From Database Give Blank EDMX Diagram

Aug 27, 2014

Yes, exactly, and I have been successfully creating EF Model before from the same database.... Why is it acting up now... I did check SO and they seems not to have a solution for it also....

View 8 Replies View Related

C++ :: Count The Repeated Numbers?

Jul 12, 2013

I am using this code that to check a set of values from a text file and show it on the output.

Code: void MatchNumber(int b) {
vector<Rect> rects;
ifstream theFile("CheckNumber.txt");
double x1,y1,x2,y2;
while(theFile >> x1 >> y1 >> x2 >> y2 ){
rects.push_back(Rect(x1,y1, x2,y2));
}
int num=0;

[code]....

I want to calculate how many times the common number is repeated . So I have used freq[num] in that function. But I am getting the output like this-

Code:

The common number is = 5
The 5 repeated = 1 times
The common number is = 6
The 6 repeated = 1 times

The common number is = 4
The 4 repeated = 1 times

The common number is = 5
The 5 repeated = 1 times

[code]....

So the freq[num] is only returning 1 instead of counting the total number of repeating which is wrong!! I would like to have somthing like this in my output -

Code:

The common number is = 5
The common number is = 6
The common number is = 4
The common number is = 5
The common number is = 5
The common number is = 8
The common number is = 9
The common number is = 6
The common number is = 6

[code]....

How can I do that?

View 3 Replies View Related

C++ :: How To Find Repeated Words

Aug 3, 2014

I'm currently on an exercise that specifies that I find any repeated words, "the the" for example, in a string, print the word that is repeated and how many times said word is repeated using a while loop that reads one word at a time and break statements when a repeated word is found. Having a bit of a falling out with iterators tonight and I'm not doing to well.

View 7 Replies View Related

C++ :: Repeated Digit In Integer

Oct 19, 2013

this code :

#include <cstdlib>
#include <iostream>
#define TRUE 1
#define FALSE 0
using namespace std;
typedef int Bool;

[Code] ....

Gives repeated digits in an integer but only in one condition : Only if the repeated digit is the result of n%10 where n is the integer the user writes. If the repeated digit is not the result of n%10 , then the compiler gives a wrong result.

so the question is : how to make this code gives the repeated digit in an integer (regardless the fact that the repeated digit is the result of n%10 or not and especially with making the minimum of changes on the code)????????? ?????

View 3 Replies View Related

C++ :: Print Repeated Array Of 2D?

Mar 23, 2014

Printing duplicate 2D array elements

if for 1D array

for (int i = 0; i<0; i++){
for (int j = i+1; j<0; i++)
{
if (arra[i] == arra[j]){
cout<<arra[i]<<endl
}
}
}

how would i do for 2D

View 5 Replies View Related

C/C++ :: Repeated Numbers In A Matrix?

Apr 18, 2014

Given the matrix MxN, check if there are repeated numbers.

View 8 Replies View Related

C++ :: Counting The Repeated Number?

Jul 12, 2013

This function check a set of values from a text file and show it on the output.

void MatchNumber(int b){
vector<Rect> rects;
ifstream theFile("CheckNumber.txt");

[Code]......

I want to calculate how many times the number is repeated. So I have used freq[num] in that function. But I am getting the output like this-

The common number is = 5
The 5 repeated = 1 times

The common number is = 6
The 6 repeated = 1 times

The common number is = 4
The 4 repeated = 1 times

The common number is = 5
The 5 repeated = 1 times

The common number is = 5
The 5 repeated = 1 times

The common number is = 8
The 8 repeated = 1 times

The common number is = 9
The 9 repeated = 1 times

The common number is = 6
The 6 repeated = 1 times

The common number is = 6
The 6 repeated = 1 times

The common number is = 8
The 8 repeated = 1 times

So the value of freq[num] only shows 1 instead of calculating the number of repetition.

View 3 Replies View Related

C/C++ :: Using Strings To Find Out If A Name Is Repeated?

Feb 10, 2014

I have to write a code that will read in n amount of names and the names. Then it will tell me if the first name entered has been repeated or not.

This is my input:

5 Bush Reagan Lincoln Bush Obama

This is my output:

First name in list is not repeated.
First name in list is not repeated.
First name in list is repeated.
First name in list is not repeated.

I would like to just give one answer; if it is repeated then the output should simply be "First name in list is repeated."

If the answer is that it was not repeated, I would like the output to say once "First name in list is not repeated."

// lastnames.c

#include <stdlib.h>
#include <stdio.h>
int main(void) {
char FIRST[25];

[code]....

View 2 Replies View Related

C++ :: Repeated Word Detection Program?

Mar 6, 2015

In the C++ book Programming: Principles and Practice Using C++, there's an example code like this for detecting repeated words:

Code:
#include "std_lib_facilities.h"
int main() {
int number_of_words = 0;
string previous = " "; // previous word; initialized to "not a word"
string current; // current word
while (cin >> current) // read a stream of words

[Code].....

The header file in there is sort of like a set of training-wheels for students who are complete beginners to the language; the function keep_window_open() is defined in there and it does just that on Windows systems where the output window closes too fast (in the case of the function, it's just like cin.ignore(), except it waits for you enter a character, like 'j', before it exits); programs on my Windows laptop work fine on Code::Blocks, but when I create a .exe file for them and double-click that file, it does actually close too quickly for me to be able to see the output (if it's a program like the generic "Hello World!" program that just outputs text to the screen and then exits - so all I see is the output window just flash-by really fast in those cases).

Anyway, as for the problem I'm having with the code: there are no error and compile- or link-time, but it does behave strangely at runtime, where the part inside the curly-braces of the while-loop doesn't execute at all.

View 3 Replies View Related

C++ :: How To Count Repeated Numbers In Array

Jan 30, 2015

So I already gave this a go and will post my code below. The question is about the last loop before the program cout's. i thought the count would keep track of the repeated numbers so i could display them but it does not. I italicized the loop i am referring to. or at least i tried to xD

#include <iostream>
#include <iomanip>
using namespace std;
int main() {
int inputs[30];
int numofloops;
int maxvalue = inputs[0];

[Code]...

View 1 Replies View Related

C/C++ :: Writing Repeated Lines To A File?

Aug 26, 2014

I am working on a problem for the CS50 online course through the Harvard web site. I am trying to re-size a bmp image. They gave us a small program that copies a bmp image and we are to modify it to re-size the image. Here is the page [URL]..... Any way I am trying to move the file position indicator backwards so I can read the same line from the input file. So I can resize the file vertically I have the image resized horizontally but it keeps over writing the same lines vertically.

/**
* bmp.h
*
* Computer Science 50
* Problem Set 5

[Code]...

View 4 Replies View Related

C/C++ :: Finding First Non-repeated Digit In Array

Aug 26, 2014

With out sorting and if the array size is changed and filled with different elements, mayb some that are all duplicates(in that case display message that says "No nonrepeated digits".

This seemed like a simple task but im failing to grasp some concept. if the array is 2,0,38,2,3,1,3 the first non repeated is 0.
nested loop is how i went. i feel like im going to far with the counters than need be. just need first non repeated. if n equals 2 an o equals 0. and it iterates comparing 0,38,2,3,1,3 to n which is 2. repCount will b 1. if repcount was 0 then n would be the first non repeated number. im trying to consolidate my if else statements so there are not so many. This program fails if the array gets bigger say 2,45,2,7,1,8,9,45,1,10 .....

for (n=0; n<sizeof(digits)/sizeof(int); n++) {
if(repCount<2) {
// nonRepCount=0;
for (o=n+1; o<sizeof(digits)/sizeof(int); o++)

[Code] .....

View 1 Replies View Related

C :: Replace Repeated Elements Within 2D (10x10) Int Array

Mar 20, 2014

I have generated a 10x10 integer matrix, by way of a 2 dimensional array, the elements are randomly generated and lie on 1 <= z <= 5. I am in need of an efficient method of setting all adjacent "duplicates" (repeating elements) of length 3 or greater to the integer six (6). The source for the brute method follows for clarity.

Code:
46 for(row=0;row<10;row++)
47 {
48 for(col=0;col<10;col++)
49 {
50 board[row][col]=rand()%4+1; //filling matrix here

[Code] .....

I know there must exist a much more elegant approach than listing out all permutations.

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved