[QUOTE=jA_cOp;31264659]I know for sure tail call optimization is performed by GCC, MSVC and ICC. But you can pretty much assume that any other mature compiler will perform it too.[/QUOTE]
Fun irrelevant fact: The Scheme spec requires that all implementations of the specific dialect of lisp do tail recursion optimization
[editline]22nd July 2011[/editline]
[QUOTE=Jookia;31264822]You shouldn't rely on optimizations that the compiler may or not make to avoid horrible program corrupting bugs.[/QUOTE]
Yeah, in most cases the iterative approach is better
[QUOTE=Jookia;31264822]You shouldn't rely on optimizations that the compiler may or not make to avoid horrible program corrupting bugs.[/QUOTE]
I would agree, but not with this particular optimization. Using recursion is integral to certain programming paradigms and many languages (example mentioned in the above post) actually require the optimization to be available. Tail call optimization is almost de-facto standard in C++.
Iteration via recursion is essential in functional languages, and that's why functional languages (like Scheme) require implementations to do proper tail recursion.
Recursion is [i]not[/i] the typical way to do iteration in C++, and the C++ standard does not require implementations to support tail recursion. Even if it's commonly implemented anyway, relying on a compiler-specific optimization for a program's correctness is a bad idea. (What happens if optimizations are turned off for debugging?)
[QUOTE=Wyzard;31268685](What happens if optimizations are turned off for debugging?)[/QUOTE]
The tail call optimization isn't even done unless you pass arguments optimizing for speed, but it's not really a problem in practice, problems only occur under certain conditions that are easily identifiable in debugging mode.
[QUOTE=Protocol7;31255036]Any SQL gurus out there?
Essentially I need to convert a column's system_type_id to the ADO type. So for example, an int is a system_type_id of 56, but the ADO type is a 3. As far as I can tell there aren't any inbuilt lookups for this purpose.[/QUOTE]
Anyone? Should I just populate a lookup table and drop it once it's done?
Im working on a swep in garrysmod (with lua)
Ive used a prop from a pack ive downloaded from garrysmod.org and i need the prop to sit properly in place where my hand is. But i have no idea what to do ?
Here the lua code
//General Settings \\
SWEP.AdminSpawnable = true // Is the swep spawnable for admin
SWEP.ViewModelFOV = 140 // How much of the weapon do u see ?
SWEP.ViewModel = "models/weapons/V_ninja.mdl" // The viewModel, the model you se when you are holding it-.-
SWEP.WorldModel = "models/weapons/V_ninja.mdl" // The worlmodel, The model yu when it's down on the ground
SWEP.AutoSwitchTo = true // when someone walks over the swep, chould i automatectly change to your swep ?
SWEP.Slot = 1 // Deside wich slot you want your swep do be in 1 2 3 4 5 6
SWEP.HoldType = "melee" // How the swep is hold Pistol smg grenade melee
SWEP.PrintName = "Beejay is ninja" // your sweps name
SWEP.Author = "Beejay" // Your name
SWEP.Spawnable = false // Can everybody spawn this swep ? - If you want only admin keep this false and adminsapwnable true.
SWEP.AutoSwitchFrom = false // Does the weapon get changed by other sweps if you pick them up ?
SWEP.FiresUnderwater = true // Does your swep fire under water ?
SWEP.Weight = 6 // Chose the weight of the Swep
SWEP.DrawCrosshair = false // Do you want it to have a crosshair ?
SWEP.Category = "Beejay" // Make your own catogory for the swep
SWEP.SlotPos = 1 // Deside wich slot you want your swep do be in 1 2 3 4 5 6
SWEP.DrawAmmo = no // Does the ammo show up when you are using it ? True / False
SWEP.ReloadSound = "Weapon_Pistol.Reload" // Reload sound, you can use the default ones, or you can use your one; Example; "sound/myswepreload.waw"
SWEP.Instructions = "Hit those guys!" // How do pepole use your swep ?
SWEP.Contact = "Debbeyaa@gmail.com" // How Pepole chould contact you if they find bugs, errors, etc
SWEP.Purpose = "Killing people?!" // What is the purpose with this swep ?
SWEP.base = "weapon_base"
//General settings\\
//PrimaryFire Settings\\
SWEP.Primary.Sound = "Weapon_Crowbar.Single" // The sound that plays when you shoot :]
SWEP.Primary.Damage = 1337 // How much damage the swep is doing
SWEP.Primary.TakeAmmo = 0 // How much ammo does it take for each shot ?
SWEP.Primary.ClipSize = 0 // The clipsize
SWEP.Primary.Ammo = "crowbar" // ammmo type pistol/ smg1
SWEP.Primary.DefaultClip = 0 // How much ammo does the swep come with `?
SWEP.Primary.Spread = 0.1 // Does the bullets spread all over, if you want it fire exactly where you are aiming leave it o.1
SWEP.Primary.NumberofShots = 1 // How many bullets you are firing each shot.
SWEP.Primary.Automatic = true // Is the swep automatic ?
SWEP.Primary.Recoil = 0 // How much we should punch the view
SWEP.Primary.Delay = 1 // How long time before you can fire again
SWEP.Primary.Force = 50 // The force of the shot
//PrimaryFire settings\\
//Secondary Fire Variables\\
SWEP.Secondary.NumberofShots = 1 // How many explosions for each shot
SWEP.Secondary.Force = 100 // Explosions Force
SWEP.Secondary.Spread = 0.1 // How much the explosion does spread
SWEP.Secondary.Sound = "Weapon_Mortar.Single" // Fire sound
SWEP.Secondary.DefaultClip = 32 // How much ammo the secoindary swep comes with
SWEP.Secondary.Automatic = false // Is it automactic ?
SWEP.Secondary.Ammo = "rpg_round" // Leave as Pistol !
SWEP.Secondary.Recoil = 2 // How uch we should punch the view
SWEP.Secondary.Delay = 3 // How long you have to wait before fire a new shot
SWEP.Secondary.TakeAmmo = 1 // How much ammo Does it take ?
SWEP.Secondary.ClipSize = 100 // ClipSize
SWEP.Secondary.Damage = 10000 -- The damage the explosion does.
SWEP.Secondary.Magnitude = "75" -- How big its the explosion ?
//Secondary Fire Variables\\
//SWEP:Initialize()\\
function SWEP:Initialize()
util.PrecacheSound(self.Primary.Sound)
util.PrecacheSound(self.Secondary.Sound)
if ( SERVER ) then
self:SetWeaponHoldType( self.HoldType )
end
end
//SWEP:Initialize()\\
//SWEP:PrimaryFire()\\
function SWEP:PrimaryAttack()
if ( !self:CanPrimaryAttack() ) then return end
local bullet = {}
bullet.Num = self.Primary.NumberofShots
bullet.Src = self.Owner:GetShootPos()
bullet.Dir = self.Owner:GetAimVector()
bullet.Spread = Vector( self.Primary.Spread * 0.1 , self.Primary.Spread * 0.1, 0)
bullet.Tracer = 0
bullet.Force = self.Primary.Force
bullet.Damage = self.Primary.Damage
bullet.AmmoType = self.Primary.Ammo
local rnda = self.Primary.Recoil * -1
local rndb = self.Primary.Recoil * math.random(-1, 1)
self:ShootEffects()
self.Owner:FireBullets( bullet )
self.Weapon:EmitSound(Sound(self.Primary.Sound))
self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
self:TakePrimaryAmmo(self.Primary.TakeAmmo)
self.Weapon:SetNextPrimaryFire( CurTime() + self.Primary.Delay )
self.Weapon:SetNextSecondaryFire( CurTime() + self.Primary.Delay )
end
//SWEP:PrimaryFire()\\
//SWEP:SecondaryFire()\\
function SWEP:SecondaryAttack()
if ( !self:CanSecondaryAttack() ) then return end
local rnda = -self.Secondary.Recoil
local rndb = self.Secondary.Recoil * math.random(-1, 1)
self.Owner:ViewPunch( Angle( rnda,rndb,rnda ) )
local eyetrace = self.Owner:GetEyeTrace()
self.Weapon:EmitSound ( self.Secondary.Sound )
self:ShootEffects()
local explode = ents.Create("env_explosion")
explode:SetPos( eyetrace.HitPos )
explode:SetOwner( self.Owner )
explode:Spawn()
explode:SetKeyValue("iMagnitude","175")
explode:Fire("Explode", 0, 0 )
explode:EmitSound("weapon_AWP.Single", 400, 400 )
self.Weapon:SetNextPrimaryFire( CurTime() + self.Secondary.Delay )
self.Weapon:SetNextSecondaryFire( CurTime() + self.Secondary.Delay )
self:TakePrimaryAmmo(self.Secondary.TakeAmmo)
end
//SWEP:SecondaryFire()\\
[QUOTE=cavel115;31269597]Im working on a swep in garrysmod (with lua)
Ive used a prop from a pack ive downloaded from garrysmod.org and i need the prop to sit properly in place where my hand is. But i have no idea what to do ?
Here the lua code
-snip-[/QUOTE]
This section is for general programming and non-GMod Lua. Perhaps try this section: [url]http://www.facepunch.com/forums/337-Questions[/url], they will probably be more help.
[QUOTE=Ziks;31269763]This section is for general programming and non-GMod Lua. Perhaps try this section: [url]http://www.facepunch.com/forums/337-Questions[/url], they will probably be more help.[/QUOTE]
People and their redirects :(... The fail sometimes :( i was redirected here d:
[QUOTE=cavel115;31269833]People and their redirects :(... The fail sometimes :( i was redirected here d:[/QUOTE]
Where were you redirected from?
And its not because we dont want to help you, its just that people over here know about things other than gmod lua (mostly)
Anyone got a good resource for XNA (4) tutorials?
[QUOTE=FlashStock;31269992]Anyone got a good resource for XNA (4) tutorials?[/QUOTE]
2d or 3d
[QUOTE=awfa3;31257618]Make a right triangle from your player to your mouse then just use trig to find the angle.[/QUOTE]
Well, what I needed was actually the math on how to do it.
[QUOTE=Richy19;31272714]2d or 3d[/QUOTE]
2d
[QUOTE=FlashStock;31273526]2d[/QUOTE]
[url]http://rbwhitaker.wikidot.com/xna-tutorials[/url]
Some cool tutorials, both 2d, 3d, and some other cool stuff like Input, Audio, etc.
[QUOTE=Staneh;31273400]Well, what I needed was actually the math on how to do it.[/QUOTE]
You have the player's position and the cursor's position, both must be ingame or screen units, not a mix. Let's say the player is at 10,10 and the cursor is at 15,20.
[img]http://pad2.whstatic.com/images/b/b7/Trigonometry-triangle-5760.png[/img]
That's a triangle. The adjacent side will be (cursorX-playerX) and the opposite will be the same, but with the Y axis. Now, to get the angle A, we'll need to do tan(opposite/adjacent). I think that's it.
[QUOTE=Jookia;31274784]You have the player's position and the cursor's position, both must be ingame or screen units, not a mix. Let's say the player is at 10,10 and the cursor is at 15,20.
That's a triangle. The adjacent side will be (cursorX-playerX) and the opposite will be the same, but with the Y axis. Now, to get the angle A, we'll need to do tan(opposite/adjacent). I think that's it.[/QUOTE]
isnt it atan?
if you have
[code] tan x = o/a [/code]
then surely
[code] x = atan (o/a) [/code]
Okay, say I had some XML files with hundreds of lines of these in :
[code] <Waypoint>121.6064 2532.279 120.1234</Waypoint>
<Waypoint>130.9865 2494.623 116.4022</Waypoint>
<Waypoint>133.9374 2463.366 137.2533</Waypoint>[/code]
How would I, say, build something that could go through the entire file and format lines like the above to look like this :
[code] <Hotspot X="121.6064" Y="2532.279" Z="120.1234" />
<Hotspot X="130.9865" Y="2494.623" Z="116.4022" />
<Hotspot X="133.9374" Y="2463.366" Z="137.2533" />[/code]
I could do it in Python or C#, but I'm not even really looking for someone to code it for me or give code examples, just a general idea of the fastest way I could handle and format lots of lines like that, one at a time. I dont have a great deal of experience with string manipulation on that scale, and its a bitch to do it by hand, even with replace.
[QUOTE=Staneh;31256883]So i'm trying to make my player rotate to the mouse, how do I do this? I know how to get my mouse coords.[/QUOTE]
Here you go (C++):
[code]double AngleToTarget(double x1,double y1,double x2,double y2)
{
double deltaX = (x2-x1);
double deltaY = (y2-y1);
return atan2(deltaY,deltaX);
}[/code]
Edit: I think you need to #include <cmath>
I'm using C#, but this seems to help, let me figure this out.
In XNA4 i want to draw my level, objects and the player.
The draw order is first level, then player and then objects.
level and objects should be drawn with the standard texture filter settings ( Linear ).
but i want the player to be rendered with the "Point" filter. (the texture should NOT be filterd. it has to be drawn pixelated just like in minecraft for example)
Currently I Begin() the spritebatch, then i call draw on each of my objects in the correct order, and then I End() the spritebatch.
Can I change the filtering mode for single DrawImage calls while inside an active spritebatch?
Or do I have to End() the spritebatch, change the filter, Start(), draw the player, End(), change the filter back to Linear, Start() ?
Or is there another way to do this?
I didn't see an overload for DrawImage that also takes texture filter settings.
How would you guys do this?
[QUOTE=Lilolia;31277877]Okay, say I had some XML files with hundreds of lines of these in :
-snip-
I could do it in Python or C#, but I'm not even really looking for someone to code it for me or give code examples, just a general idea of the fastest way I could handle and format lots of lines like that, one at a time. I dont have a great deal of experience with string manipulation on that scale, and its a bitch to do it by hand, even with replace.[/QUOTE]
You could always use an XML parser.
Parse it to an array of double[3] then put it back into XML or just use string concatenation
[QUOTE=Lilolia;31277877]Okay, say I had some XML files with hundreds of lines of these in :
[code] <Waypoint>121.6064 2532.279 120.1234</Waypoint>
<Waypoint>130.9865 2494.623 116.4022</Waypoint>
<Waypoint>133.9374 2463.366 137.2533</Waypoint>[/code]
How would I, say, build something that could go through the entire file and format lines like the above to look like this :
[code] <Hotspot X="121.6064" Y="2532.279" Z="120.1234" />
<Hotspot X="130.9865" Y="2494.623" Z="116.4022" />
<Hotspot X="133.9374" Y="2463.366" Z="137.2533" />[/code]
I could do it in Python or C#, but I'm not even really looking for someone to code it for me or give code examples, just a general idea of the fastest way I could handle and format lots of lines like that, one at a time. I dont have a great deal of experience with string manipulation on that scale, and its a bitch to do it by hand, even with replace.[/QUOTE]
For a simple thing like this forget things like regex or XML parsers.
Also no need to parse it to doubles.
Pass each line to this:
[B][I][U]C#[/U][/I][/B]
[code]
static string ReformatString(string Input)
{
Input = Input.Replace("<Waypoint>", "");
Input = Input.Replace("</Waypoint>", "");
string[] numbers = Input.Split(' ');
return String.Format("<Hotspot X=\"{0}\" Y=\"{1}\" Z=\"{2}\" />", numbers[0], numbers[1], numbers[2]);
}
[/code]
I really like C# for things like this.
Because for productivity tools you almost never need (excellent) performance. It's all about getting it done!
Always remember, "the right tools for the job..."
[QUOTE=Felheart;31278508]If you only have "hundreds", fuck performance and do this
[B][I][U]C#[/U][/I][/B]
[code]
static string ReformatString(string Input)
{
Input = Input.Replace("<Waypoint>", "");
Input = Input.Replace("</Waypoint>", "");
string[] numbers = Input.Split(' ');
return String.Format("<Hotspot X=\"{0}\" Y=\"{1}\" Z=\"{2}\" />", numbers[0], numbers[1], numbers[2]);
}
[/code]
I really like C# for things like this.
Because for productivity tools you almost never need (excellent) performance. It's all about getting it done!
Always remember, "the right tools for the job..."[/QUOTE]
Thats awesome, thanks!
The code I came up with was pretty terrible in comparison.
*EDIT*
Since I'm still learning Python I figured I'd rewrite yours in it, and its pretty much the same. Still way better than I had done it before, I have learned something!
[code]def ReformatString(Input):
Input = Input.replace ('<Waypoint>', '')
Input = Input.replace ('</Waypoint>', '')
numbers = Input.split()
return ' <Hotspot> X="%s" Y="%s" Z="%s" />' % (numbers[0], numbers[1], numbers[2])
[/code]
I'm at a loss here about this error: Basically I am writing this game that has one main class called application which has all the other managers(classes) in it so that I only have to pass that class down. But every time I try to implement this I end up receiving all these errors about missing type identifiers. I read around the internet and based on what I found the problem was that I defined the classes to be used later in the header, but hey weren't defined yet or something also something about recursive class definition(I can't find the website and I don't remember what it said nor did I understand it)
Anyway here's the code, hoping someone knows what I'm doing wrong, if you don't I'd appreciate if someone knew a better way to write a game framework and told me about it.
There are other files but these are the most important ones:
I've also commented with //C4430 on the part that give me "error C4430: missing type specifier - int assumed. Note: C++ does not support default-int" errors.
application.h:
[code]#ifndef APP_H
#define APP_H
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include "gameManager.h"
class application
{
sf::Clock elapsedTime;
public:
sf::RenderWindow *App;
gameManager mm; //C4430
void consoleWrite(char* text, bool timestamp = true)
{
if(timestamp)
std::cout << elapsedTime.GetElapsedTime() << ": " << text << std::endl;
else
std::cout << text << std::endl;
}
application()
{
consoleWrite("Creating RenderWindow");
App = new sf::RenderWindow(sf::VideoMode(800,800,32),"test");
App->SetFramerateLimit(60);
mm.init(App);
}
bool isOpened()
{
return App->IsOpened();
}
void run()
{
App->Clear();
mm.think();
App->Display();
}
};
#endif
[/code]
gameManager.h:
[code]
#include <SFML/Graphics.hpp>
#include <SFML/Window.hpp>
#include <SFML/System.hpp>
#include <iostream>
#include "map.h"
#include "application.h"
class gameManager
{
sf::Image sfmlLogo;
sf::Sprite sfmlSprite;
application *App; //C4430
UIManager menuButtons; //C4430
int state;
float mainTick;
float fader;
public:
void init(application *tApp)
{
App = tApp;
map testmap;
menuButtons.init(App);
menuButtons.allocateButton(sf::Vector2f(620,720),"Start game",0);
menuButtons.allocateButton(sf::Vector2f(20,720),"Quit game",0);
fader = 255;
state = 0;
mainTick = 0;
sfmlLogo.LoadFromFile("res/mainmenu/sfml.png");
sfmlSprite.SetImage(sfmlLogo);
sfmlSprite.SetPosition(400-sfmlLogo.GetWidth()/2,400-sfmlLogo.GetHeight()/2);
}
void newGame()
{
}
void think()
{
if(state == 0)
{
mainTick++;
if(mainTick < 120)
{
App->Clear(sf::Color(255,255,255));
App->Draw(sfmlSprite);
}
if(mainTick > 119 && mainTick < 220)
{
App->Clear(sf::Color(255,255,255));
sfmlSprite.SetColor(sf::Color(255,255,255,fader-=2.5));
App->Draw(sfmlSprite);
}
if(mainTick > 219)
state = 1;
}
if(state == 1)
{
menuButtons.update();
}
}
};
[/code]
[QUOTE=FPSMango;31281663]I'm at a loss here about this error: Basically I am writing this game that has one main class called application which has all the other managers(classes) in it so that I only have to pass that class down. But every time I try to implement this I end up receiving all these errors about missing type identifiers. I read around the internet and based on what I found the problem was that I defined the classes to be used later in the header, but hey weren't defined yet or something also something about recursive class definition(I can't find the website and I don't remember what it said nor did I understand it)
Anyway here's the code, hoping someone knows what I'm doing wrong, if you don't I'd appreciate if someone knew a better way to write a game framework and told me about it.
There are other files but these are the most important ones:
I've also commented with //C4430 on the part that give me "error C4430: missing type specifier - int assumed. Note: C++ does not support default-int" errors.
application.h:
[code]<code snoop>[/code]
gameManager.h:
[code]<code snipe>[/code][/QUOTE]
You have a circular dependency; gameManager.h includes application.h and vice-versa. It doesn't know how to resolve it!
To fix it, look at what each header needs to know about the other thing and see if you can devise a third class to handle that stuff.
This, i discovered painfully FPSMango, is why you need header and implementation files
Wow, I don't really know where to start understanding this, does any of you know of any good tutorial/writeups on circular dependency, I can only find fragments and small examples when I search for it.
I am intrigued by this for example but I don't really know what to do to use it:
[img]http://interactiveasp.net/cfs-filesystemfile.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image21.png[/img]
I'm a bit of a beginner, so could anyone help me? I have the OpenGL Superbible 4th Edition and the source files that came with it, would anyone who owns the book help me set up to start using OpenGL if I'm using Visual Studio 2008?
[QUOTE=FPSMango;31282454]Wow, I don't really know where to start understanding this, does any of you know of any good tutorial/writeups on circular dependency, I can only find fragments and small examples when I search for it.
I am intrigued by this for example but I don't really know what to do to use it:
[img]http://interactiveasp.net/cfs-filesystemfile.ashx/__key/CommunityServer.Blogs.Components.WeblogFiles/natesstuff/image21.png[/img][/QUOTE]
Depends on what the "Common" is. Database is the first that comes to mind, but maybe a business object (which goes down to a database anyway lol) but I can't really think of anything else.
[editline]22nd July 2011[/editline]
[QUOTE=amazer97;31283029]I'm a bit of a beginner, so could anyone help me? I have the OpenGL Superbible 4th Edition and the source files that came with it, would anyone who owns the book help me set up to start using OpenGL if I'm using Visual Studio 2008?[/QUOTE]
If you're a beginner, OpenGL may not be the best starting point.
[QUOTE=Protocol7;31283109]Depends on what the "Common" is. Database is the first that comes to mind, but maybe a business object (which goes down to a database anyway lol) but I can't really think of anything else.
[editline]22nd July 2011[/editline]
If you're a beginner, OpenGL may not be the best starting point.[/QUOTE]
No, what I meant was I'm a beginner at OpenGL. I've been programming for around 2 years now, but the book doesn't really specify what libraries you need, or where to get them / what versions to get. I was wondering if someone else who completed the Superbible 4th Edition knew what I need exactly.
Sorry, you need to Log In to post a reply to this thread.