added mesh rendering

This commit is contained in:
2025-05-28 14:36:57 +03:00
parent 60fa98e240
commit b83078553e
53 changed files with 1436 additions and 363 deletions

View File

@@ -1,7 +1,9 @@
#ifndef ENTITY_H
#define ENTITY_H
#include "engine.h"
#include "tier1/utlvector.h"
#include "cglm/cglm.h"
class CBaseEntity;
class C_BaseEntity;
@@ -19,20 +21,21 @@ struct Triangle_t
class CBaseEntity
{
public:
C_BaseEntity *pClientEntity;
CBaseEntity();
virtual void Precache() = 0;
virtual void Spawn( void ) = 0;
virtual void Destroy( void ) = 0;
virtual void Think( float fDelta ) = 0;
C_BaseEntity *pClientEntity;
mat4 m_matrix;
};
extern CUtlSelfReferencingVector<CBaseEntity*> g_entities;
typedef CBaseEntity*(*EntityRegistryFn)( void );
typedef C_BaseEntity*(*ClientEntityRegistryFn)( void );
class CEntityRegistry
interface CEntityRegistry
{
public:
CEntityRegistry( const char *szName, const char *szClass, EntityRegistryFn pfn );
@@ -43,7 +46,6 @@ public:
ClientEntityRegistryFn m_pClientfn;
};
extern CUtlVector<CEntityRegistry*> g_RegisteredEntities;
#define DECLARE_ENTITY(name, class) \
@@ -66,9 +68,10 @@ public:
virtual void Destroy( void ) = 0;
/* happens every frame instead of tick */
virtual void Think( float fDelta ) = 0;
private:
};
class C_EntityRegistry
interface C_EntityRegistry
{
public:
C_EntityRegistry( const char *pName, ClientEntityRegistryFn pfn );
@@ -82,6 +85,8 @@ C_BaseEntity *__c_entity_alloc_##server() \
C_EntityRegistry __c_entity_##server##_registry(#server, __c_entity_alloc_##server); \
extern CUtlSelfReferencingVector<CBaseEntity*> g_entities;
extern CUtlVector<CEntityRegistry*> g_RegisteredEntities;
#endif

View File

@@ -1,7 +1,7 @@
#ifndef CONSOLE_H
#define CONSOLE_H
#include "tier0/platform.h"
#include "engine.h"
#include "tier1/utlstring.h"
class ConVar;
@@ -95,4 +95,4 @@ void Msg( const char* message );
void Warning( const char* message );
void Error( const char* message );
#endif
#endif

View File

@@ -1,6 +1,7 @@
#ifndef ENGINE_H
#define ENGINE_H
/* for windows as it sucks */
#include "tier0/platform.h"
class CBaseEntity;
@@ -17,11 +18,9 @@ public:
interface IIEngine
{
public:
static void PrecacheModel( const char *psz );
static void PrecacheSound( const char *psz );
static CBaseEntity *SpawnEntity( const char *szName );
static void DestroyEntity( CBaseEntity *pEntity );
};
#endif

View File

@@ -3,6 +3,7 @@
#include "tier0/platform.h"
#include "tier1/utlbuffer.h"
#include "tier1/utlstring.h"
#include "engine.h"
enum EFileOptions
{

View File

@@ -1,7 +1,7 @@
#ifndef LEVEL_H
#define LEVEL_H
#include "tier0/platform.h"
#include "engine.h"
interface ILevel
{

View File

@@ -60,6 +60,8 @@ struct px_cast_result px_box_cast(struct funnyphysics *px_world,
struct px_vec3 vel,
float time);
void px_fixedbody(struct funnyphysics *px_world, Collider *collider);
void px_frame(struct funnyphysics *px_world, float delta);
struct px_matrix px_getmatrix(struct funnyphysics *px_world, RigidBodyHandle *body);

View File

@@ -29,20 +29,6 @@ public:
virtual void Unmap() = 0;
};
abstract_class IBrush
{
public:
virtual void SetPosition( vec3 position ) = 0;
virtual void SetRotationEuler( vec3 angle ) = 0;
virtual void SetRotationQuat( vec4 quaternion) = 0;
virtual void SetMatrix( mat3 matrix ) = 0;
virtual void SetScale( vec3 scale ) = 0;
virtual void SetVertexBuffer( IVertexBuffer *pBuffer ) = 0;
virtual void SetIndexBuffer( IIndexBuffer *pBuffer ) = 0;
virtual void Draw() = 0;
};
enum EMaterialType
{
IMATERIAL_ERROR = 0,
@@ -82,20 +68,64 @@ public:
Material_t m;
};
interface IRenderer
{
public:
static IVertexBuffer *CreateVertexBuffer( uint32_t uSize );
static IIndexBuffer *CreateIndexBuffer( uint32_t uSize );
static IMaterial *LoadMaterial( const char *szName );
static void SetMaterial( IMaterial *pMaterial );
};
//----------------------------------------------------------------------------
// Brush handler for the rendering
//----------------------------------------------------------------------------
abstract_class IBrush
{
public:
virtual void SetVertexBuffer( IVertexBuffer *pBuffer ) = 0;
virtual void SetIndexBuffer( IIndexBuffer *pBuffer ) = 0;
virtual void Draw() = 0;
};
interface IBrushRenderer
{
public:
static void Init();
static void Frame( float fDelta );
static IVertexBuffer *CreateVertexBuffer( uint32_t uSize );
static IIndexBuffer *CreateIndexBuffer( uint32_t uSize );
static IBrush *CreateMesh();
static void Destroy( IBrush *pModel );
};
static IMaterial *LoadMaterial( const char *szName );
static void SetMaterial( IMaterial *pMaterial );
//----------------------------------------------------------------------------
// Mesh handler for the rendering
//----------------------------------------------------------------------------
abstract_class IMesh
{
public:
virtual void SetPosition( vec3 position ) = 0;
virtual void SetRotationEuler( vec3 angle ) = 0;
virtual void SetRotationQuat( vec4 quaternion) = 0;
virtual void SetMatrix( mat4 matrix ) = 0;
virtual void SetScale( vec3 scale ) = 0;
virtual void SetVertexBuffer( IVertexBuffer *pBuffer ) = 0;
virtual void SetIndexBuffer( IIndexBuffer *pBuffer ) = 0;
virtual void Draw() = 0;
};
interface IMeshRenderer
{
public:
static void Init();
static void Frame( float fDelta );
static IMesh *CreateMesh();
static void Destroy( IBrush *pModel );
};
abstract_class ITexture

View File

@@ -4,6 +4,16 @@
#include "stdint.h"
#include "stddef.h"
#ifdef __WIN32__
#define DLL_EXPORT extern "C" __declspec(dllexport)
#define DLL_IMPORT extern "C" __declspec(dllimport)
#define DLL_CLASS_EXPORT __declspec(dllexport)
#define DLL_CLASS_IMPORT __declspec(dllimport)
#define DLL_GLOBAL_EXPORT extern __declspec(dllexport)
#define DLL_GLOBAL_IMPORT extern __declspec(dllimport)
#else
#define DLL_EXPORT extern "C" __attribute__ ((visibility("default")))
#define DLL_IMPORT extern "C"
@@ -12,6 +22,7 @@
#define DLL_GLOBAL_EXPORT extern __attribute ((visibility("default")))
#define DLL_GLOBAL_IMPORT extern
#endif
#ifdef TIER0_STATIC

View File

@@ -320,4 +320,4 @@ void CUtlSelfReferencingVector<T>::RemoveTail( void )
}
#endif
#endif