aboutsummaryrefslogtreecommitdiff
path: root/src/object_properties.h
blob: 79866a22c4ba8949f639d7c34e80f3cded067b22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
Minetest
Copyright (C) 2013 celeron55, Perttu Ahola <celeron55@gmail.com>

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#pragma once

#include <string>
#include "irrlichttypes_bloated.h"
#include <iostream>
#include <map>
#include <vector>
#include "util/Optional.h"

struct ObjectProperties
{
	u16 hp_max = 1;
	u16 breath_max = 0;
	bool physical = false;
	bool collideWithObjects = true;
	// Values are BS=1
	aabb3f collisionbox = aabb3f(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f);
	aabb3f selectionbox = aabb3f(-0.5f, -0.5f, -0.5f, 0.5f, 0.5f, 0.5f);
	bool pointable = true;
	std::string visual = "sprite";
	std::string mesh = "";
	v3f visual_size = v3f(1, 1, 1);
	std::vector<std::string> textures;
	std::string damage_texture_modifier = "^[brighten";
	std::vector<video::SColor> colors;
	v2s16 spritediv = v2s16(1, 1);
	v2s16 initial_sprite_basepos;
	bool is_visible = true;
	bool makes_footstep_sound = false;
	f32 stepheight = 0.0f;
	float automatic_rotate = 0.0f;
	bool automatic_face_movement_dir = false;
	f32 automatic_face_movement_dir_offset = 0.0f;
	bool backface_culling = true;
	s8 glow = 0;
	std::string nametag = "";
	video::SColor nametag_color = video::SColor(255, 255, 255, 255);
	Optional<video::SColor> nametag_bgcolor = nullopt;
	f32 automatic_face_movement_max_rotation_per_sec = -1.0f;
	std::string infotext;
	//! For dropped items, this contains item information.
	std::string wield_item;
	bool static_save = true;
	float eye_height = 1.625f;
	float zoom_fov = 0.0f;
	bool use_texture_alpha = false;
	bool shaded = true;
	bool show_on_minimap = false;

	ObjectProperties();
	std::string dump();
	// check limits of some important properties (strings) that'd cause exceptions later on
	bool validate();
	void serialize(std::ostream &os) const;
	void deSerialize(std::istream &is);
};
"hl opt">: SharedPtr(T *t=NULL) { refcount = new int; *refcount = 1; ptr = t; } SharedPtr(SharedPtr<T> &t) { //*this = t; drop(); refcount = t.refcount; (*refcount)++; ptr = t.ptr; } ~SharedPtr() { drop(); } SharedPtr<T> & operator=(T *t) { drop(); refcount = new int; *refcount = 1; ptr = t; return *this; } SharedPtr<T> & operator=(SharedPtr<T> &t) { drop(); refcount = t.refcount; (*refcount)++; ptr = t.ptr; return *this; } T* operator->() { return ptr; } T & operator*() { return *ptr; } bool operator!=(T *t) { return ptr != t; } bool operator==(T *t) { return ptr == t; } T & operator[](unsigned int i) { return ptr[i]; } private: void drop() { assert((*refcount) > 0); (*refcount)--; if(*refcount == 0) { delete refcount; if(ptr != NULL) delete ptr; } } T *ptr; int *refcount; }; template <typename T> class Buffer { public: Buffer() { m_size = 0; data = NULL; } Buffer(unsigned int size) { m_size = size; if(size != 0) data = new T[size]; else data = NULL; } Buffer(const Buffer &buffer) { m_size = buffer.m_size; if(m_size != 0) { data = new T[buffer.m_size]; memcpy(data, buffer.data, buffer.m_size); } else data = NULL; } Buffer(const T *t, unsigned int size) { m_size = size; if(size != 0) { data = new T[size]; memcpy(data, t, size); } else data = NULL; } ~Buffer() { drop(); } Buffer& operator=(const Buffer &buffer) { if(this == &buffer) return *this; drop(); m_size = buffer.m_size; if(m_size != 0) { data = new T[buffer.m_size]; memcpy(data, buffer.data, buffer.m_size); } else data = NULL; return *this; } T & operator[](unsigned int i) const { return data[i]; } T * operator*() const { return data; } unsigned int getSize() const { return m_size; } private: void drop() { if(data) delete[] data; } T *data; unsigned int m_size; }; template <typename T> class SharedBuffer { public: SharedBuffer() { m_size = 0; data = NULL; refcount = new unsigned int; (*refcount) = 1; } SharedBuffer(unsigned int size) { m_size = size; if(m_size != 0) data = new T[m_size]; else data = NULL; refcount = new unsigned int; (*refcount) = 1; } SharedBuffer(const SharedBuffer &buffer) { //std::cout<<"SharedBuffer(const SharedBuffer &buffer)"<<std::endl; m_size = buffer.m_size; data = buffer.data; refcount = buffer.refcount; (*refcount)++; } SharedBuffer & operator=(const SharedBuffer & buffer) { //std::cout<<"SharedBuffer & operator=(const SharedBuffer & buffer)"<<std::endl; if(this == &buffer) return *this; drop(); m_size = buffer.m_size; data = buffer.data; refcount = buffer.refcount; (*refcount)++; return *this; } /* Copies whole buffer */ SharedBuffer(const T *t, unsigned int size) { m_size = size; if(m_size != 0) { data = new T[m_size]; memcpy(data, t, m_size); } else data = NULL; refcount = new unsigned int; (*refcount) = 1; } /* Copies whole buffer */ SharedBuffer(const Buffer<T> &buffer) { m_size = buffer.getSize(); if(m_size != 0) { data = new T[m_size]; memcpy(data, *buffer, buffer.getSize()); } else data = NULL; refcount = new unsigned int; (*refcount) = 1; } ~SharedBuffer() { drop(); } T & operator[](unsigned int i) const { //assert(i < m_size) return data[i]; } T * operator*() const { return data; } unsigned int getSize() const { return m_size; } operator Buffer<T>() const { return Buffer<T>(data, m_size); } private: void drop() { assert((*refcount) > 0); (*refcount)--; if(*refcount == 0) { if(data) delete[] data; delete refcount; } } T *data; unsigned int m_size; unsigned int *refcount; }; inline SharedBuffer<u8> SharedBufferFromString(const char *string) { SharedBuffer<u8> b((u8*)string, strlen(string)+1); return b; } #endif