C++ :: Ioquake3 Engine - Accessing Limited Struct Fields

Feb 29, 2012

I'm currently working on the ioquake3 engine . The ioquake3 engine is separated into 2 different main threads at runtime: the gamecode and the engine. Both are communicating but not all information and my problem resides here.

In the gamecode, there's a struct called gentity_t which contains a lot of fields:

Code:
typedef struct gentity_s gentity_t;
struct gentity_s {
entityState_ts;// communicated by server to clients
entityShared_tr;// shared by both the server system and game
// DO NOT MODIFY ANYTHING ABOVE THIS, THE SERVER
// EXPECTS THE FIELDS IN THAT ORDER!
//================================
struct gclient_s*client;// NULL if not a client

[Code] ....

This whole entity is passed to the engine at runtime, but only the first two fields are declared for the engine:

Code:
// the server looks at a sharedEntity, which is the start of the game's gentity_t structure
typedef struct {
entityState_ts;// communicated by server to clients
entityShared_tr;// shared by both the server system and game
} sharedEntity_t;

My problem is that I need to access the health field of gentity_t from the engine. Technically, this is possible, but the health field is not declared in sharedEntity (which is the same memory address than gentity_t in the gamecode), so this is not straightforward.

I am looking for an elegant way to do this, and my constraint is that I must not edit the gamecode, only the engine.

The solutions I've thought:

- Just copy the whole gentity_t fields into sharedEntity_t. This would work I think but would be redundant, and I would like to avoid copying this huge set of fields.

- Include the two headers files declaring the gentity_t and sharedEntity_t structs, and create a Getter and a Setter functions that would cast a gentity_t over a sharedEntity_t and return/set a field. The problem is that I can't simply include them because they are both including some common headers files and this produce a recursive include error (and I can't modify the files to add a check, these are normally in the gamecode).

- Directly access the health field using a clever memory pointer, but I don't even know if that's possible given the huge number of fields prior health with many different types?

View 2 Replies


ADVERTISEMENT

C :: How To Create Private Fields In A Struct

Nov 6, 2014

How can you actually create private fields in a C struct? I got the concept of VTable and inheriting methods aswell overriding them, but private variables can be obtained with static keyword in sourcefile. If you have variables in a struct, you can access them as soon as you got a ref to the struct. The functions are easy:

Code:

struct classA {
pointerToFunction *p;
} static void* thePrivateFoo() { }
void* publicFoo() {
thePrivateFoo(); /* or something like that */
} ...
/*in init code somewhere in the c file */ classAInstance->p = publicFoo;

But I was thinking about the variables... How is this achievable? I was thinking of a struct with only get/set functions and with no datamembers at all. All vars to be static outside the struct. But this kind of destroys the encapsulation.

View 4 Replies View Related

C++ :: Template Return Struct Fields

Dec 2, 2014

is it possible to define as template the following get functions.

class Config {
public:
enum { NO_ID = 999 };
struct ValueType {
bool a;
size_t b;
std::time_t c;

[code]....

View 6 Replies View Related

C++ :: Input To Fields In A Struct And Pass Function To Display - Error C2365

Oct 21, 2014

Goal: Use a struct that has 4 fields, input to those fields, and pass to function to display.

Problem: (38) : error C2365: 'displaySData' : redefinition; previous definition was 'data variable'

Code:
#include <iostream>
#include <string>
using namespace std;
//prototypes
void displaySData(MovieData, MovieData);

[Code] .....

View 3 Replies View Related

C++ :: Accessing Inside Structure Via Struct Pointer To Struct Pointer

Jun 5, 2012

"
#include <stdio.h>
struct datastructure {
char character;
};
void function(struct datastructure** ptr);

[Code] ....

These codes give these errors:

error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'
error: request for member 'character' in '* ptr', which is of non-class type 'datastructure*'

These errors are related to
"
*ptr->character='a';
printf("Ptr: %c",*ptr->character);
"

I want to access "character" data inside the structure "trial" by a pointer to pointer "ptr" inside function "function",but I couldn't find a way to do this.

View 3 Replies View Related

C++ ::  Accessing Struct Data In A Queue

Mar 24, 2013

I have a queue of structs. I would like to access one of the two pieces of data at the front of the queue that each struct maintains.

Here is some of my code:

#include <iostream>
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <queue>
using namespace std;

[Code] ....

What I am asking is how do I get the priority of the struct item at the front (lane1.front()), in this case?

View 8 Replies View Related

C/C++ :: Segfault When Accessing Member Of A Struct

Mar 18, 2014

The program I'm working on is a very basic relational database. I've isolated my problem for simplicity. I get a segfault right here when I try to access db->relationCount. I tried printing db->relationCount from within loadDB and that worked,

[code]
loadDB(db, configFile);
printf("%d",db->relationCount);
fflush(stdout);

View 5 Replies View Related

C/C++ :: Accessing Elements Of Struct Array

Dec 9, 2014

I've been working for some number of days on this code to take information about movies from both a file and the user, store the infos in an array of structs, and at the end, write all the info out to a file. I'm having some problems with an error message reading:

"prog.c:102:11: error: subscripted value is neither array nor pointer nor vector"

this error occurs in many lines (which I will label specifically below -- they are everywhere where I am trying to access/modify an individual element of a struct element of the array).

A few examples of where I am having the problems are lines:
39, 52-55, 70, 72, and 86 (and more of the same exact variety).

I am obviously rather systematically doing something wrong, but I am quite certain all of these are the exact same mistakes.

I pull up also 2 or 3 other errors, but I don't think they are related and should be able to fix them quickly once I work out this conundrum.

#include <string.h>
#include<stdlib.h>
#include <stdio.h>
int moviecount =0;
typedef struct{
int year;

[Code] .....

View 5 Replies View Related

C++ :: Accessing Private Members Of Same Struct Type

Mar 26, 2013

I've been reading the tutorials on Friendship and Inheritance [URL] ..... but I still don't understand why I can't access members of the same struct type.

bool wordBeginsAt (int pos) {
if (pos == 0)
return true;

///use the 'message' string
Message go;
return isAlphanumeric(go.messageText[pos]) && (!isAlphanumeric(go.messageText[pos-1]));
}

The code above is located in a source file, where the function isAlphanumeric passes a char value, and Message is the struct containing the string I want to access. Below is the declaration of the struct and string located in the corresponding header file.

struct Message{
.
.
.
private:
std::string messageText;
};

My frustration comes when I try to call and assign messageText like the tutorial does to its private members, but I keep getting an error saying I can't access the string because it is a private member. Is there a way to access the string without having to pass it through the function wordBeginsAt?

View 6 Replies View Related

C++ :: Accessing Pointed-to Value In A Struct Vector Of Pointers?

Apr 30, 2013

I have a vector (structures) in a struct (instances). I make a declaration of this struct called instance. The vector is a 3-layer vector of pointers, like so:

vector < vector < vector<scene::IAnimatedMeshSceneNode*> > > structures; (The type is from Irrlicht 3D). I have 3 nested "for" loops which looks similar to the following:

for (int a = 0; a < instance.structures.size(); a++) { /*note:vector size previously set*/
for (int b = 0; b < instance.structures[a].size(); b++){
for (int c = 0; c < instance.structures[a][b].size(); c++) {

if (1) { //checking value of variable not included in snippet

(instance.structures)[a][b][c] = smgr->addAnimatedMeshSceneNode(fl);
(instance.structures)[a][b][c]->setPosition(renderPos);
}
}
}
}

The problem is in these two lines, I think:

(instance.structures)[a][b][c] = smgr->addAnimatedMeshSceneNode(fl);
(instance.structures)[a][b][c]->setPosition(renderPos);

These are currently referencing the pointers, it seems. The program compiles but crashes at this point. I need them to reference the values of the pointers. Problem is, I don't know where to put the dereference operator (*). Where should it go?

View 4 Replies View Related

C :: Linear Search Function Accessing String In A Struct?

Apr 5, 2013

I currently have a file which allows inputs to record different transistor types. I then have the task of accessing this structure, find a certain manufacturer ID, and print the information about this particular transistor.

My problem is accessing the array to search through.

Here is my code:

Code:
#include "stdio.h"
const int IDLEN=30; //All constant values defined
const int POLARITYLEN=3;
const int MAXSTOCKITEMS=10;
//First structure defined
struct TransistorRec {

[Code]......

The errors I am currently getting are on line 54 'expected primary-expression before "struct"' and on line 60 ' 'maunfacturersID' undeclared'

View 11 Replies View Related

C :: Parsing Binary Data File By Casting A Buffer - Accessing Double From Struct

Jan 4, 2014

I am parsing a binary data file by casting a buffer to a struct. It seems to work really well apart from this one double which is always being accessed two bytes off, despite being in the correct place.

Code:

typedef struct InvoiceRow {
uint INVOICE_NUMBER;
...
double GROSS;
...
char VAT_NUMBER[31];
} InvoiceRow;

If I attempt to print GROSS using printf("%f", row->GROSS) I get 0.0000. However, if I change the type of GROSS to char[8] and then use the following code, I am presented with the correct number...

Code:

typedef struct example {
double d;
}

example;
example *blah = (example*)row->GROSS;
printf("%f", blah->d);

View 7 Replies View Related

C++ :: VC Thread Arguments Number Limited?

Mar 2, 2013

I am using thread on VC 2012 (very close to VC 2010). When the argument list is short, it works fine. However, when I add a function with more arguments, the compiler indicates "no thread constructor match the argument list....etc", and when I reduce the number of arguments, it works.

Is there a limit about thread constructor? I didn't see this in ISO C++11 standard. How can I fix this limit?

View 5 Replies View Related

C++ :: Limited Purpose Calculator Which Finds Value Of One Of Five Operations

Jan 9, 2015

I just started learning C++ a week ago and have been stuck on a project for the past 2 days now. I am building a limited purpose calculator which finds the value of one of five operations. Visual studio doesn't underline any errors in my program but every time I try to run it I get an error message. I believe it has something to do with the if/else but Im not sure.

#include <iostream>
using namespace std;
int main(){
int a;
int b;
int sum = a + b;

[Code] ....

View 5 Replies View Related

C :: Comparison Is Always False Due To Limited Data Type Error

Feb 16, 2013

Code:

do {
printf("Edit the entry's cellphone number:");
scanf("%s", addressbook[4][num]);
length = strlen(addressbook[4][num]); //gets the length of the input (should be 10)
//checks if the input is composed of 11 elements wherein the first 2 are 0 and 9 respectively
for(i=0; i<11; i++){

[Code] ....

why do I get an error here?

Code:
if ((addressbook[4][num][0] == '0') && (addressbook[4][num][1] == '9') || (addressbook[4][num][i]>='0') && (addressbook[4][num][i]<='9') && (length=='11'))

And how do I fix this?

The error message is: comparison is always false due to limited data type

View 1 Replies View Related

C Sharp :: How To Add Local Database In Install Shield Limited Edition

Nov 26, 2014

I have small Project In Vs 2013.i have to deploy it.but i did through Installshield. Project is working same PC but when i try to deploy another PC i cannot loin in to my project.it seems to me that i didn't add database .

View 2 Replies View Related

C++ :: Drag And Drop 3D Engine

Nov 16, 2013

How to create a 3D Drag and Drop Game Engine?

View 19 Replies View Related

C++ :: Simplest 3D Physics Engine

Jan 18, 2013

What is the simplest 3D physics engine that you have used, that works well?

All I need to be able to represent is a spherical ground (planet), one or more tetrahedrons, with 1 or 0 cylinders coming out of each face, which might connect to other tetrahedrons. The tetrahedrons and cylinders have weight and can rotate around their connection point in 1 direction.

Basically, they are simple digital robots that need to walk around, so I don't need something with the complexity of Havok or Newton.

View 1 Replies View Related

C++ :: Game Engine - Finding A Constructor

Mar 18, 2013

I'm making a small game engine and have a project in Code::Blocks for it, and a project to test it out. The thing is that my test program won't find a constructor from the engine. Here's my code:

Game Engine, Screen.hpp

#ifndef SCREEN_HPP_INCLUDED
#define SCREEN_HPP_INCLUDED
#include "SDL.h"
namespace myeng {
class Screen final //This class doesn't need to be derived from

[Code] ....

I have my engine project correctly linking to the SDL dlls and the test project linking to the engine dll and the SDL dlls. The errors are:

objDebugmain.o||In function `SDL_main':|
C:UsersMainDocumentsProgramsGame_Engine_Testmain.cpp|12|undefined reference to `myeng::Screen::Screen(int, int)'|
C:UsersMainDocumentsProgramsGame_Engine_Testmain.cpp|16|undefined reference to `myeng::Screen::~Screen()'|
||=== Build finished: 2 errors, 0 warnings ===|

View 7 Replies View Related

C++ :: Create 3D Game Engine With OpenGL?

Jul 19, 2013

What i'm trying to do is create a 3d game engine with opengl and i want to be multi platform. I'm trying to use code-blocks for this reason but i'm having trouble setting up opengl for code-blocks

View 1 Replies View Related

C# :: Program Design - Database Search Engine

Apr 12, 2014

I am building a semi-complicated program and the focus of it will be on the search engine. The current plan is for it to search an online database after keywords and receive a list of responses organized by relevance.

I want to minimize the stress on the server by handling as much of the process on the client side as possible so I wonder how best to split up the tasks.

So far my idea is to have the client send the search term to the server who then compare it with its registry. Collecting the 30 or so most relevant hits it sends it back along with additional information from each entry. Requesting additional hits will be decided by sending a simple int value telling which page its filling up.

Simple example:

"Search word" gets processed by the client to account for spelling errors, context etc (based on what I can implement by myself). An Int value gets added (0 for page 1, 1 for page 2 etc...). The request gets sent to the server who can immediately run the search without processing the search word since that was handled in the client. It locates hits and order them by relevance then send out the information batch decided by the Int.

View 2 Replies View Related

C++ :: Game Engine - Linking Error On MinGW

Aug 6, 2013

I want to write a game engine with MinGW and Code::blocks ide

[URL] ....

This is my project's source code

[URL] .....

This is the build log.

I can't code it here, because it's two large to add the characters!

View 10 Replies View Related

C++ :: Game Engine - Instancing A Class Via Constructor

Apr 23, 2013

I'm making a little "game engine" for a Rogue-Like game series I'll develop beside a friend. This "game engine" was programmed originally in ms-dos batch 6 years ago by me, and was evolving since. It have a VB6 version, a VB .net version, and a Python version... lately a C++ version following the same method of the first stable release of ms-dos batch (isn't weird?). As you can see, is a mere hobby.

Well, I have 1 headers for my C++ version of the engine, in that *.h file I have 2 classes (for now). The first class, and maybe the most important one, contains the code of the map handling (drawing, verification, creation, modification etc.) and the second one is the Object class, which code the "actors" or "npc" basic functions as movement, coloring, instancing etc...

The second class depends of the first class to function, because the first class is the responsible of displaying all inside the map.

The problem is that the class Object needs an instance of the class Map where the Object will be, but... that's the problem, the code seems right, but when is about to run it crash reporting a "No matching function for call to 'Map::Map()'" in the line 91 of AGE.h (that's the Object class constructor)... and its all.

So, this is the code of the main header that contains these classes:

#include <iostream>
#include <stdlib.h>
#include <conio.h>
#define Up 0
#define Down 1
#define Left 2

[Code] ....

A simple code that uses "AGE.h" for test purposes...

View 7 Replies View Related

C :: Laser Project Tile Engine Doesn't Work

Aug 27, 2013

I should reduce the number of bitmaps I used in my code. I translated my particle engine into code that could be compiled as plain standard C

Currently, the code has a segmentation fault somewhere that I can't figure out. How it should function is that it takes orders from a queue for new lasers to store the instances in a linked list. It then takes that data and updates its coordinates, one node at a time. The first node should also be the first node to complete its life, so it gets removed, and the list is set to the next node in memory. If there are no more nodes left, a if-statement should catch it and either break the current loop, or wait for more items to be requested. If there are nodes left, the process will continue to remove the first node in the list until there are none left. Obviously this is not quite how it works. When I tested in once in SDL, the laser would update every 5 frames, but wasn't shown constantly, and would crash after the node was to be disposed of. When I initialize with the SDL parachute, it would exit before I event saw the screen. Also, the code I translated to standard C will display that the laser has been updated to the screen, but it never says that it has moved up. It crashes after about 4 printf() statments execute. My debugger has been giving me mixed SIGTRAPS, and "nothing is wrong" output. Here is the code in standard C:

Code:

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define MAX_LASER_QUEUE 10
}

[code]....

View 6 Replies View Related

C++ :: Using Set To Get Fields From Reader XML

Mar 28, 2013

I am using set in my code to get fields from a reader xml which are being errored out but it is storing it in ordered form(i.e it is internally sorting it) not in accordance to how the reader xml has the fields. What should i do so that it write the errored file in accordance to the reader xml.

View 1 Replies View Related

C++ :: How To Get Fields From Reader XML

Mar 28, 2013

I am using set in my code to get fields from a reader xml which are being errored out but it is storing it in ordered form(i.e it is internally sorting it) not in accordance to how the reader xml has the fields.What should i do so that it write the errored file in accordance to the reader xml.

View 8 Replies View Related







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