Skip to content

scripts_system::script

Paweł Waligóra edited this page Apr 16, 2024 · 17 revisions

Full signature: class scripts_system::script

namespace scripts_system {
	class script {
	public:
		bool active = true;
		virtual void init() {};
		virtual void start() {};
		virtual void update() {};
		virtual void free() {};
	};
}

Class is meant to be abstract. Should be overridden. Place your custom classes that inherit from scripts_system::script in namespace game

  • methods
    • scripts_system::script::init() - called during opengl init, use for memory allocation.
    • scripts_system::script::start() - called once just before game loop, use for setup
    • scripts_system::script::update() - called ever iteration of game loop
    • scripts_system::script::free() - called on opengl free, use for freeing memory allocated on game::script::init()

All methods are called by scripts_system::call_events(), after object has been registered with: scripts_system::subscribe(&object). Methods can be registered individually with: scripts_system::subscribe(std::bind(&game::your_script::method, &object), SCRIPTS_TYPE), where SCRIPTS_TYPE can be one of the following:

  • SCRIPTS_INIT
  • SCRIPTS_START
  • SCRIPTS_UPDATE
  • SCRIPTS_FREE

Usage Example

my_script.h

#pragma once
#include "scripts_system.h"

namespace game {
	class my_script : public scripts_system::script {
	public:
		virtual void init();
		virtual void start();
		virtual void update();
		virtual void free();

		// other public members

	private:
		// private members
	};
}

my_script.cpp

#include "my_script.h"

void game::my_script::init() {
	// this code will execute once on program init
}

void game::my_script::start() {
	// this code will execute once just before game loop
}

void game::my_script::update() {
	// this code will execute once every program step
}

void game::my_script::free() {
	// this code will execute once on program free
}

// other members definitions

Home

Git Workflow

Issues

Coding Rules

Skrypty-Tutorial

Useful resources

Game Structure

Code Structure

Clone this wiki locally