• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Psychopathetica

Boolean issues

4 posts in this topic

I am terribly confused as to why something so simple on other programming languages could be total hell on C++. Ok heres the problem. I have a struct inside a header. And I made an extern variable declared as that structure.

#ifndef INTRO_H
#define INTRO_H

#include "DX.h"

struct Intro_Type
{
	bool Enabled;
	float Time;
	float Milliseconds;
	float Speed;
	LPDIRECT3DTEXTURE9 Texture;
	float Fade;
	CUSTOM_VERTEX Vertex_List[3];
};

void Load_Blizzard_Logo_Texture();
void Draw_Blizzard_Logo();
void Intro_Loop();

extern Intro_Type Blizzard_Logo;
extern Intro_Type Blizzard_Hold;
extern Intro_Type Blizzard_Fade;

#endif

Basically I'm trying to recreate the intro screen (which is shown before the actual title screen) to the game I was working on off another programming language and porting it to C++. Simple fade in, show a logo for a few seconds and fade out. Problem is, is that the boolean variable Enabled for Blizzard_Hold is not triggering even though the logic behind the code should trigger it. The only time it works is when I have Draw_Blizzard_Logo() commented out.

void Intro_Loop()
{
    Get_Elapsed_Time = (float)timeGetTime();
    if (Blizzard_Logo.Enabled == true)
    {
        Blizzard_Logo.Time = (Get_Elapsed_Time - Blizzard_Logo.Milliseconds) / 1000.0f;
        Fade = int(Blizzard_Fade.Speed * Blizzard_Logo.Time);
        if (Fade > 255)
        {
            Fade = 255;
            
            Blizzard_Logo.Enabled = false;
            Blizzard_Hold.Enabled = true;
            Blizzard_Hold.Milliseconds = Get_Elapsed_Time;
        }
    }
    if (Blizzard_Hold.Enabled == true)
    {
        Blizzard_Hold.Time = (Get_Elapsed_Time - Blizzard_Hold.Milliseconds) / 1000.0f;
        if (Blizzard_Hold.Time >= 5.0f)
        {
            Blizzard_Hold.Enabled = false;
            Blizzard_Fade.Enabled = true;
            Blizzard_Fade.Milliseconds = Get_Elapsed_Time;
        }
    }
    
    if (Blizzard_Fade.Enabled == true)
    {
        Blizzard_Fade.Time = (Get_Elapsed_Time - Blizzard_Fade.Milliseconds) / 1000.0f;
        Fade = 255 - (int)(Blizzard_Fade.Speed * Blizzard_Fade.Time);
        if (Fade <= 0.0f)
        {
            Fade = 0;
            Blizzard_Fade.Enabled = false;
        }
    }
    Draw_Blizzard_Logo(Fade);
}

Basically all the booleans trigger just fine when Draw_Blizzard_Logo(Fade); is commented out. But if its not commented out and I'm displaying the logo, it does the first if statement just fine, but doesn't trigger the next if statement because Blizzard_Hold.Enabled is still false even after Fade >= 255. The only code I got inside that sub routine Draw_Blizzard_Logo is this which shouldn't even effect the if statements at all:

void Draw_Blizzard_Logo(int Fade)
{
	if (Fullscreen_Enabled)
	{
		Blizzard_Logo.Vertex_List[0] = Create_Custom_Vertex(0, 0, 0, 1, D3DCOLOR_RGBA(255, 255, 255, Fade), 0, 0);
		Blizzard_Logo.Vertex_List[1] = Create_Custom_Vertex((float)Screen.BackBufferWidth, 0, 0, 1, D3DCOLOR_RGBA(255, 255, 255, Fade), 1, 0);
		Blizzard_Logo.Vertex_List[2] = Create_Custom_Vertex(0, (float)Screen.BackBufferHeight, 0, 1, D3DCOLOR_RGBA(255, 255, 255, Fade), 0, 1);
		Blizzard_Logo.Vertex_List[3] = Create_Custom_Vertex((float)Screen.BackBufferWidth, (float)Screen.BackBufferHeight, 0, 1, D3DCOLOR_RGBA(255, 255, 255, Fade), 1, 1);
	}
	else
	{
		Blizzard_Logo.Vertex_List[0] = Create_Custom_Vertex(0, 0, 0, 1, D3DCOLOR_RGBA(255, 255, 255, Fade), 0, 0);
		Blizzard_Logo.Vertex_List[1] = Create_Custom_Vertex((float)Window_Width, 0, 0, 1, D3DCOLOR_RGBA(255, 255, 255, Fade), 1, 0);
		Blizzard_Logo.Vertex_List[2] = Create_Custom_Vertex(0, (float)Window_Height, 0, 1, D3DCOLOR_RGBA(255, 255, 255, Fade), 0, 1);
		Blizzard_Logo.Vertex_List[3] = Create_Custom_Vertex((float)Window_Width, (float)Window_Height, 0, 1, D3DCOLOR_RGBA(255, 255, 255, Fade), 1, 1);
	}
	Device->SetRenderState(D3DRS_ALPHABLENDENABLE, true);
	Device->SetTexture(0, Blizzard_Logo.Texture);
	Device->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, Blizzard_Logo.Vertex_List, sizeof(CUSTOM_VERTEX));
}

Could anyone tell me what I'm doing wrong? I hope I was clear enough about everything. I'm stumpted o.O

Edited by Psychopathetica
0

Share this post


Link to post
Share on other sites

In C++, basic variables like bools and ints aren't initialized automaticly. Your bools won't start off false, but they start off in a unpredictable state. I can't see in your code whether you are properly initializing them or not.

 

You can give the struct a non-default constructor to properly initialize the member variables:

struct Intro_Type
{ 
	Intro_Type() : Enabled(false), Time(0.0f), Milliseconds(0.0f), Speed(0.0f), Texture(...), Fade(0.0f)
	{
		Vertex_List[0] = {...};
		Vertex_List[1] = {...};
		Vertex_List[2] = {...};
	}

	bool Enabled;
	float Time;
	float Milliseconds;
	float Speed;
	LPDIRECT3DTEXTURE9 Texture;
	float Fade;
	CUSTOM_VERTEX Vertex_List[3];
};

Alternatively, if you use a compiler that supports the latest C++ standard (C++11), and have C++11 enabled, you can do this:

struct Intro_Type
{ 
	bool Enabled = false;
	float Time = 0.0f;
	float Milliseconds = 0.0f;
	float Speed = 0.0f;
	LPDIRECT3DTEXTURE9 Texture = ...;
	float Fade = 0.0f;
	CUSTOM_VERTEX Vertex_List[3] = {{...},{...},{...}};
};

With C++, uninitialized variables are kinda like playing russian roulette - you don't know what values are in the variables, so doing if (Blizzard_Logo.Enabled == true) might prove true some of the times your program is ran, and might prove false other times, unpredictably.

2

Share this post


Link to post
Share on other sites

I actually initialized all of em when the program starts. Didnt show it cause it wasn't necessary but Blizzard_Logo.Enabled was true and the other 2 were false ;)

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0